package com.engine.qz.service.impl;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.engine.core.impl.Service;
import com.engine.qz.service.MeritsService;
import com.engine.salary.util.report.SalaryReportUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.BaseBean;
import weaver.general.Util;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

/**
 * @version 1.0
 * @Title ecology-9
 * @Company 泛微软件
 * @CreateDate 2024/11/4
 * @Description 绩效
 * @Author AdminZm
 */
public class MeritsServiceImpl extends Service implements MeritsService {

    BaseBean baseBean = new BaseBean();

    @Override
    public Map<String, Object> generateIndexDt(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        baseBean.writeLog("generateIndexDt start:" + params);
        try {
            // 考核计划
            String khjh = Util.null2String(params.get("khjh"));
            if (StringUtils.isEmpty(khjh)) {
                baseBean.writeLog("generateIndexDt khjh is null.");
                result.put("mes", "请选择考核计划！");
                result.put("code", "200");
                return result;
            }

            String khfas = null;
            String szny = null;
            String jhksrq = null;
            RecordSet rs = new RecordSet();
            rs.execute("SELECT szkhfa, szny, jhksrq FROM uf_khjhdy WHERE id = " + khjh);
            if (rs.next()) {
                khfas = rs.getString("szkhfa");
                szny = rs.getString("szny");
                jhksrq = rs.getString("jhksrq");
            }

            if (StringUtils.isEmpty(khfas)) {
                baseBean.writeLog("generateIndexDt khfa is null.");
                result.put("mes", "未查到对应考核方案，请检查！");
                result.put("code", "200");
                return result;
            }

            // 获取考核计划所属年月、计划开始日期
            if (StringUtils.isEmpty(szny) || StringUtils.isEmpty(jhksrq)) {
                baseBean.writeLog("generateIndexDt szny is null.");
                result.put("mes", "考核计划所属周期获取失败，请检查！");
                result.put("code", "200");
                return result;
            }

            // 先删除该考核计划关联的原人员指标
            rs.execute("SELECT id FROM uf_ygmxzbdy WHERE szkhjh = " + khjh);
            List<String> idList = new ArrayList<>();
            while (rs.next()) {
                String oldId = rs.getString("id");
                if (StringUtils.isEmpty(oldId)) {
                    continue;
                }
                idList.add(oldId);
            }
            if (!CollectionUtils.isEmpty(idList)) {
                int batchSize = 100; // 每个小集合的大小
                int size = idList.size(); // 原始集合的大小
                int numberOfBatches = (int) Math.ceil((double) size / batchSize); // 划分的小集合数量
                List<List<String>> dividedLists = new ArrayList<>(); // 存储划分后的小集合

                for (int i = 0; i < numberOfBatches; i++) {
                    int fromIndex = i * batchSize;
                    int toIndex = Math.min((i + 1) * batchSize, size);
                    List<String> batch = idList.subList(fromIndex, toIndex);
                    dividedLists.add(batch);
                }

                for (List<String> batch : dividedLists) {
                    String ids = String.join(",", batch);
                    rs.execute("delete from uf_ygmxzbdy WHERE id in (" + ids + ")");
                    rs.execute("delete from uf_ygmxzbdy_dt1 WHERE mainid in (" + ids + ")");
                }
            }

            LocalDate currentDate = LocalDate.now();

            // 获取人员负责部门数量
            rs.execute("SELECT id,bmfzr FROM hrmdepartment where bmfzr is not null");
            Map<String, Integer> bmCntMap = new HashMap<>();
            while (rs.next()) {
                String bmId = rs.getString("id");
                String bmfzr = rs.getString("bmfzr");
                if (StringUtils.isEmpty(bmfzr)) {
                    continue;
                }
                String[] bmfzrArr = bmfzr.split(",");
                for (String r : bmfzrArr) {
                    if ((!CollectionUtils.isEmpty(bmCntMap)) && bmCntMap.containsKey(r)) {
                        Integer integer = bmCntMap.get(r);
                        bmCntMap.put(r, integer + 1);
                    } else {
                        bmCntMap.put(r, 1);
                    }
                }
            }

            // 定义一个DateTimeFormatter对象，用于解析年月字符串
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
            DateTimeFormatter formatterRq = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            // 将字符串解析为YearMonth对象
            YearMonth yearMonth = YearMonth.parse(szny, formatter);
            // 从YearMonth对象中提取年份与月份
            int year = yearMonth.getYear();
            int month = yearMonth.getMonthValue();
            int lastDay = yearMonth.lengthOfMonth();

            // 获取保护期人员
            Set<String> protectSet = new HashSet<>();
            rs.executeQuery("SELECT ygxm FROM uf_khbhqxxrg WHERE lx = 1 AND ((YEAR(CONVERT(date, ksrq)) = ? AND MONTH(CONVERT(date, ksrq)) = ?)" +
                    " OR (YEAR(CONVERT(date, jsrq)) = ? AND MONTH(CONVERT(date, jsrq)) = ?))", year, month, year, month);
            while (rs.next()) {
                String ygxm = rs.getString("ygxm");
                if (StringUtils.isNotEmpty(ygxm)) {
                    protectSet.add(ygxm);
                }
            }

            // 获取所有调动人员对应最新日期
            Map<String, String> ddrqMap = new HashMap<>();
            rs.execute("SELECT yg, Max(shenxrq) AS ddrq FROM uf_rzjl where bdsj = 2 GROUP BY yg");
            while (rs.next()) {
                String yg = rs.getString("yg");
                String ddrq = rs.getString("ddrq");
                if (StringUtils.isEmpty(yg) || StringUtils.isEmpty(ddrq)) {
                    continue;
                }
                ddrqMap.put(yg, ddrq);
            }

            // 岗位fieldId 3
            String gwFieldId = rs.getPropValue("qz_jx_zm_prop", "gw_field_id");
            // 职级fieldId 3
            String zjFieldId = rs.getPropValue("qz_jx_zm_prop", "zj_field_id");

            // 获取人员对应分部、部门、聚才林岗位
            Map<String, String> fbMap = new HashMap<>();
            Map<String, String> bmMap = new HashMap<>();
            Map<String, String> gwMap = new HashMap<>();
            rs.execute("SELECT a.id,a.subcompanyid1,a.departmentid,b." + gwFieldId + " FROM hrmresource a LEFT JOIN cus_fielddata b " +
                    " ON a.id = b.id AND b.scope = 'HrmCustomFieldByInfoType' AND b.scopeid = 3 ");
            while (rs.next()) {
                String ryIdT = rs.getString("id");
                String subcompanyid1 = rs.getString("subcompanyid1");
                String departmentid = rs.getString("departmentid");
                String jclGw = rs.getString(gwFieldId);
                if (StringUtils.isEmpty(ryIdT)) {
                    continue;
                }
                fbMap.put(ryIdT, subcompanyid1);
                bmMap.put(ryIdT, departmentid);
                gwMap.put(ryIdT, jclGw);
            }

            // 处理调动逻辑
            // 获取“融资顾问”和“销售副经理-P”岗位id
            Set<String> tsGwIdSet = new HashSet<>();
            rs.execute("SELECT id FROM uf_JCL_GWGL WHERE gwmc = '融资顾问' OR (gwmc = '销售副经理' AND szzwxl = 2)");
            while (rs.next()) {
                String tsGwId = rs.getString("id");
                if (StringUtils.isNotEmpty(tsGwId)) {
                    tsGwIdSet.add(tsGwId);
                }
            }

            String dyeshStr = szny + "-20";
            String dyshStr = szny + "-10";
            String dyyhStr = szny + "-01";
            String dyzhhStr = szny + "-" + lastDay;
            LocalDate dyeshLd = LocalDate.parse(dyeshStr, formatterRq);
            LocalDate dyshLd = LocalDate.parse(dyshStr, formatterRq);
            LocalDate dyyhLd = LocalDate.parse(dyyhStr, formatterRq);
            LocalDate dyzhhLd = LocalDate.parse(dyzhhStr, formatterRq);

            // 获取所属年月第一个工作日日期
            String holidayGroupId = rs.getPropValue("qz_jx_zm_prop", "holiday_groupId");
            if (StringUtils.isEmpty(holidayGroupId)) {
                holidayGroupId = "8";
            }
            Set<String> holidaySet = new HashSet<>();
            Set<String> dpgzrdaySet = new HashSet<>();
            rs.executeQuery("select holidayDate,changeType from KQ_HolidaySet where groupId = ?", holidayGroupId);
            while (rs.next()) {
                String holidayDate = rs.getString("holidayDate");
                String changeType = rs.getString("changeType");
                if (StringUtils.isNotEmpty(holidayDate) && StringUtils.isNotEmpty(changeType)) {
                    BigDecimal changeTypeBd = new BigDecimal(changeType);
                    if (changeTypeBd.compareTo(new BigDecimal("1")) == 0 || changeTypeBd.compareTo(new BigDecimal("3")) == 0) {
                        holidaySet.add(holidayDate);
                    }
                    if (changeTypeBd.compareTo(new BigDecimal("2")) == 0) {
                        dpgzrdaySet.add(holidayDate);
                    }
                }
            }
            String firstWd = "";
            for (int i = 0; i < 365 ; i++) {
                LocalDate ldTemp = dyyhLd.plusDays(i);
                if (CollectionUtils.isEmpty(holidaySet) || !holidaySet.contains(ldTemp.toString())) {
                    if ((!CollectionUtils.isEmpty(dpgzrdaySet)) && dpgzrdaySet.contains(ldTemp.toString())) {
                        firstWd = ldTemp.toString();
                        break;
                    } else {
                        DayOfWeek dayOfWeek = ldTemp.getDayOfWeek();
                        if (dayOfWeek != DayOfWeek.SATURDAY && dayOfWeek != DayOfWeek.SUNDAY) {
                            firstWd = ldTemp.toString();
                            break;
                        }
                    }
                }
            }
            if (StringUtils.isEmpty(firstWd)) {
                baseBean.writeLog("generateIndexDt firstWd is null.");
                result.put("mes", "第一个工作日获取失败！");
                result.put("code", "200");
                return result;
            }
            baseBean.writeLog("generateIndexDt firstWd is:" + firstWd);
            LocalDate firstWdLd = LocalDate.parse(firstWd, formatterRq);

            Map<String, String> sxGwMap = new HashMap<>();
            Map<String, String> sxBmMap = new HashMap<>();
            Map<String, String> sxFbMap = new HashMap<>();
            Map<String, String> sxZjMap = new HashMap<>();
            Map<String, String> sxYgxzMap = new HashMap<>();
            Map<String, String> sxZtMap = new HashMap<>();
            Map<String, String> ygDdJgMap = new HashMap<>();
            Map<String, List<Map<String, String>>> rzjlListMap = new HashMap<>();
            Set<String> rzjlSecSet = new HashSet<>();
            rs.execute("SELECT * FROM uf_rzjl where yg is not null and shenxrq <= '" + dyzhhStr
                    + "' ORDER BY yg,shenxrq ASC ");
            while (rs.next()) {
                String yg = rs.getString("yg");
                String bdsj = rs.getString("bdsj");
                String shenxrq = rs.getString("shenxrq");
                String sxrq = rs.getString("sxrq");
                if (StringUtils.isEmpty(yg) || StringUtils.isEmpty(bdsj) || StringUtils.isEmpty(shenxrq) || StringUtils.isEmpty(sxrq)) {
                    continue;
                }
                LocalDate shenxrqLd = LocalDate.parse(shenxrq, formatterRq);
                // 所属月份之后生效的数据不考虑
                if (shenxrqLd.isAfter(dyzhhLd)) {
                    continue;
                }
                String bdqbm = rs.getString("bdqbm");
                String bdhbm = rs.getString("bdhbm");
                String bdqgw = rs.getString("bdqgw");
                String bdhgw = rs.getString("bdhgw");
                String bdqzj = rs.getString("bdqzj");
                String bdhzj = rs.getString("bdhzj");
                String bdqygxz = rs.getString("bdqygxz");
                String bdhygxz = rs.getString("bdhygxz");
                String bdqzt = rs.getString("bdqzt");
                if (StringUtils.equals(bdqzt, "3")) {
                    bdqzt = "0";
                }
                String bdhzt = rs.getString("bdhzt");
                if (StringUtils.equals(bdhzt, "3")) {
                    bdhzt = "0";
                }
                String bdqfb = rs.getString("bdqfb");
                String bdhfb = rs.getString("bdhfb");
                Map<String, String> rzjlMap = new HashMap<>();
                rzjlMap.put("yg", yg);
                rzjlMap.put("bdsj", bdsj);
                rzjlMap.put("shenxrq", shenxrq);
                rzjlMap.put("bdqbm", bdqbm);
                rzjlMap.put("bdhbm", bdhbm);
                rzjlMap.put("bdqgw", bdqgw);
                rzjlMap.put("bdhgw", bdhgw);
                rzjlMap.put("bdqzj", bdqzj);
                rzjlMap.put("bdhzj", bdhzj);
                rzjlMap.put("bdqygxz", bdqygxz);
                rzjlMap.put("bdhygxz", bdhygxz);
                rzjlMap.put("bdqzt", bdqzt);
                rzjlMap.put("bdhzt", bdhzt);
                rzjlMap.put("sxrq", sxrq);
                rzjlMap.put("bdqfb", bdqfb);
                rzjlMap.put("bdhfb", bdhfb);
                List<Map<String, String>> rzjlMapList = new ArrayList<>();
                if ((!CollectionUtils.isEmpty(rzjlListMap)) && rzjlListMap.containsKey(yg)) {
                    rzjlMapList = rzjlListMap.get(yg);
                }
                rzjlMapList.add(rzjlMap);
                rzjlListMap.put(yg, rzjlMapList);

                if (shenxrq.contains(szny) && StringUtils.equals(bdsj, "2") && shenxrqLd.isBefore(dyeshLd)) {
                    rzjlSecSet.add(yg);
                }
            }

            baseBean.writeLog("generateIndexDt rzjlListMap is:" + rzjlListMap);
            for (Map.Entry<String, List<Map<String, String>>> rzjlListEntry : rzjlListMap.entrySet()) {
                String ygTemp = rzjlListEntry.getKey();
                List<Map<String, String>> rzjlListTemp = rzjlListEntry.getValue();
                if (StringUtils.isEmpty(ygTemp) || CollectionUtils.isEmpty(rzjlListTemp)) {
                    continue;
                }
                String dqGwTemp = gwMap.get(ygTemp);
                if (StringUtils.isEmpty(dqGwTemp)) {
                    continue;
                }
                boolean isFirst = true;
                boolean entryRes = true;
                boolean departRes = true;
                boolean updateRes = true;
                LocalDate dataSign = dyyhLd;
                if ((!CollectionUtils.isEmpty(rzjlSecSet)) && rzjlSecSet.contains(ygTemp)) {
                    dataSign = dyzhhLd;
                    isFirst = false;
                }
                String sign = "1";
//                for (int i = 0; i < rzjlListTemp.size(); i++) {
//                    Map<String, String> rzjlMapTemp = rzjlListTemp.get(i);
//                    String shenxrq = rzjlMapTemp.get("shenxrq");
//                    String sxrq = rzjlMapTemp.get("sxrq");
//                    String bdsj = rzjlMapTemp.get("bdsj");
//                    String bdqzt = rzjlMapTemp.get("bdqzt");
//                    String bdhzt = rzjlMapTemp.get("bdhzt");
//
//                    if (StringUtils.isEmpty(sxrq)) {
//                        sxrq = "9999-12-31";
//                    }
//                    if (StringUtils.isEmpty(shenxrq) || StringUtils.isEmpty(sxrq) || StringUtils.isEmpty(bdsj)) {
//                        continue;
//                    }
//                    LocalDate shenxrqLd = LocalDate.parse(shenxrq, formatterRq);
//                    LocalDate sxrqLd = LocalDate.parse(sxrq, formatterRq);
//
//                    if ((!dyshLd.isBefore(shenxrqLd)) && dyshLd.isBefore(sxrqLd)) {
//                        if (!StringUtils.equals(bdsj, "3")) {
//                            sxZtMap.put(ygTemp, bdhzt);
//                        } else {
//                            sxZtMap.put(ygTemp, bdqzt);
//                        }
//                    }
//                }
                for (int i = 0; i < rzjlListTemp.size(); i++) {
                    Map<String, String> rzjlMapTemp = rzjlListTemp.get(i);
                    String shenxrq = rzjlMapTemp.get("shenxrq");
                    String sxrq = rzjlMapTemp.get("sxrq");
                    String bdhbm = rzjlMapTemp.get("bdhbm");
                    String bdqbm = rzjlMapTemp.get("bdqbm");
                    String bdhgw = rzjlMapTemp.get("bdhgw");
                    String bdsj = rzjlMapTemp.get("bdsj");
                    String bdqgw = rzjlMapTemp.get("bdqgw");
                    String bdqzj = rzjlMapTemp.get("bdqzj");
                    String bdhzj = rzjlMapTemp.get("bdhzj");
                    String bdqygxz = rzjlMapTemp.get("bdqygxz");
                    String bdhygxz = rzjlMapTemp.get("bdhygxz");
                    String bdqzt = rzjlMapTemp.get("bdqzt");
                    String bdhzt = rzjlMapTemp.get("bdhzt");
                    String bdqfb = rzjlMapTemp.get("bdqfb");
                    String bdhfb = rzjlMapTemp.get("bdhfb");

                    if (StringUtils.isEmpty(sxrq)) {
                        sxrq = "9999-12-31";
                    }
                    if (StringUtils.isEmpty(shenxrq) || StringUtils.isEmpty(sxrq) || StringUtils.isEmpty(bdsj)) {
                        continue;
                    }
                    LocalDate shenxrqLd = LocalDate.parse(shenxrq, formatterRq);
                    LocalDate sxrqLd = LocalDate.parse(sxrq, formatterRq);

                    if ((!dyshLd.isBefore(shenxrqLd)) && dyshLd.isBefore(sxrqLd)) {
                        if (!StringUtils.equals(bdsj, "3")) {
                            sxZtMap.put(ygTemp, bdhzt);
                        } else {
                            sxZtMap.put(ygTemp, bdqzt);
                        }
                    }
                    if (isFirst) {
//                        if (((!dataSign.isBefore(shenxrqLd)) && (dataSign.isBefore(sxrqLd))) ||
//                                ((StringUtils.equals(bdsj, "0") || StringUtils.equals(bdsj, "1") || StringUtils.equals(bdsj, "3")) && dataSign.isBefore(sxrqLd))) {
                        if ((sxrqLd.isAfter(dyzhhLd) && !shenxrqLd.isAfter(dyzhhLd)) || (sxrqLd.isAfter(dyyhLd) && !shenxrqLd.isAfter(dyyhLd))
                                || (sxrqLd.isBefore(dyzhhLd) && !shenxrqLd.isBefore(dyyhLd))) {
                            if (!StringUtils.equals(bdsj, "3")) {
                                sxGwMap.put(ygTemp, bdhgw);
                                sxBmMap.put(ygTemp, bdhbm);
                                sxFbMap.put(ygTemp, bdhfb);
                                sxZjMap.put(ygTemp, bdhzj);
                                sxYgxzMap.put(ygTemp, bdhygxz);
//                                sxZtMap.put(ygTemp, bdhzt);
                            } else {
                                sxGwMap.put(ygTemp, bdqgw);
                                sxBmMap.put(ygTemp, bdqbm);
                                sxFbMap.put(ygTemp, bdqfb);
                                sxZjMap.put(ygTemp, bdqzj);
                                sxYgxzMap.put(ygTemp, bdqygxz);
//                                sxZtMap.put(ygTemp, bdqzt);
                            }
//                            break;
                        }
                    } else {
                        if ((sxrqLd.isAfter(dyzhhLd) && !shenxrqLd.isAfter(dyzhhLd)) || (sxrqLd.isAfter(dyyhLd) && !shenxrqLd.isAfter(dyyhLd))
                                || (sxrqLd.isBefore(dyzhhLd) && !shenxrqLd.isBefore(dyyhLd))) {
                            if (!StringUtils.equals(bdsj, "3")) {
                                sxGwMap.put(ygTemp, bdhgw);
                                sxBmMap.put(ygTemp, bdhbm);
                                sxFbMap.put(ygTemp, bdhfb);
                                sxZjMap.put(ygTemp, bdhzj);
                                sxYgxzMap.put(ygTemp, bdhygxz);
                                sxZtMap.put(ygTemp, bdhzt);
                            } else {
                                sxGwMap.put(ygTemp, bdqgw);
                                sxBmMap.put(ygTemp, bdqbm);
                                sxFbMap.put(ygTemp, bdqfb);
                                sxZjMap.put(ygTemp, bdqzj);
                                sxYgxzMap.put(ygTemp, bdqygxz);
                                sxZtMap.put(ygTemp, bdqzt);
                            }
                        }
                    }
                }
                for (Map<String, String> rzjlMapTemp : rzjlListTemp) {
                    String shenxrq = rzjlMapTemp.get("shenxrq");
                    String sxrq = rzjlMapTemp.get("sxrq");
                    String bdhbm = rzjlMapTemp.get("bdhbm");
                    String bdhgw = rzjlMapTemp.get("bdhgw");
                    String bdsj = rzjlMapTemp.get("bdsj");
                    String bdqgw = rzjlMapTemp.get("bdqgw");
                    String bdqzj = rzjlMapTemp.get("bdqzj");
                    String bdhzj = rzjlMapTemp.get("bdhzj");
                    String bdqygxz = rzjlMapTemp.get("bdqygxz");
                    String bdhygxz = rzjlMapTemp.get("bdhygxz");
                    String bdqzt = rzjlMapTemp.get("bdqzt");
                    String bdhzt = rzjlMapTemp.get("bdhzt");
                    if (StringUtils.isEmpty(shenxrq) || StringUtils.isEmpty(sxrq) || StringUtils.isEmpty(bdsj)) {
                        continue;
                    }
                    LocalDate shenxrqLd = LocalDate.parse(shenxrq, formatterRq);
//                    LocalDate sxrqLd = LocalDate.parse(sxrq, formatterRq);
//                    if (((!dataSign.isBefore(shenxrqLd)) && (dataSign.isBefore(sxrqLd))) || (isFirst && StringUtils.equals(bdsj, "0") && dataSign.isBefore(sxrqLd))) {
//                        sxGwMap.put(ygTemp, bdhgw);
//                        sxBmMap.put(ygTemp, bdhbm);
//                        sxZjMap.put(ygTemp, bdhzj);
//                        sxYgxzMap.put(ygTemp, bdhygxz);
//                        sxZtMap.put(ygTemp, bdhzt);
//                    }
                    if (isFirst) {
                        if ((!CollectionUtils.isEmpty(tsGwIdSet)) && tsGwIdSet.contains(dqGwTemp)) {
                            if (StringUtils.equals(bdsj, "0")) {
                                if (!shenxrqLd.isAfter(dyshLd)) {
                                    entryRes = true;
                                } else {
                                    entryRes = false;
                                }
                            }
                            if (StringUtils.equals(bdsj, "3")) {
                                if (shenxrqLd.isBefore(dyeshLd) && StringUtils.equals(sxrq, "9999-12-31")) {
                                    departRes = false;
                                } else {
                                    departRes = true;
                                }
                            }
                        } else {
                            if (StringUtils.equals(bdsj, "0")) {
                                if (!shenxrqLd.isAfter(firstWdLd)) {
                                    entryRes = true;
                                } else {
                                    entryRes = false;
                                }
                            }
                            if (StringUtils.equals(bdsj, "3")) {
                                if (shenxrqLd.isBefore(dyeshLd) && StringUtils.equals(sxrq, "9999-12-31")) {
                                    departRes = false;
                                } else {
                                    departRes = true;
                                }
                            }
                        }
                    } else {
                        if ((!CollectionUtils.isEmpty(tsGwIdSet)) && tsGwIdSet.contains(dqGwTemp)) {
                            if (StringUtils.equals(bdsj, "0")) {
                                if (!shenxrqLd.isAfter(dyshLd)) {
                                    entryRes = true;
                                } else {
                                    entryRes = false;
                                }
                            }
                            if (StringUtils.equals(bdsj, "2")) {
                                if (StringUtils.isNotEmpty(bdqgw) && StringUtils.isNotEmpty(bdhgw)) {
                                    if (tsGwIdSet.contains(bdqgw)) {
                                        if (tsGwIdSet.contains(bdhgw)) {
                                            updateRes = true;
                                        } else {
                                            updateRes = false;
                                        }
                                    } else {
                                        if (!shenxrqLd.isAfter(dyshLd)) {
                                            updateRes = true;
                                        } else {
                                            updateRes = false;
                                        }
                                    }
                                } else {
                                    updateRes = false;
                                }
                            }
                            if (StringUtils.equals(bdsj, "3")) {
                                if (shenxrqLd.isBefore(dyeshLd) && StringUtils.equals(sxrq, "9999-12-31")) {
                                    departRes = false;
                                } else {
                                    departRes = true;
                                }
                            }
                        } else {
                            if (StringUtils.equals(bdsj, "0")) {
                                if (!shenxrqLd.isAfter(firstWdLd)) {
                                    entryRes = true;
                                } else {
                                    entryRes = false;
                                }
                            }
                            if (StringUtils.equals(bdsj, "2")) {
                                if (!shenxrqLd.isAfter(firstWdLd)) {
                                    updateRes = true;
                                } else {
                                    updateRes = false;
                                }
                            }
                            if (StringUtils.equals(bdsj, "3")) {
                                if (shenxrqLd.isBefore(dyeshLd) && StringUtils.equals(sxrq, "9999-12-31")) {
                                    departRes = false;
                                } else {
                                    departRes = true;
                                }
                            }
                        }
                    }
                }

                if (isFirst) {
                    if (entryRes && departRes) {
                        ygDdJgMap.put(ygTemp, "0");
                    } else {
                        ygDdJgMap.put(ygTemp, "1");
                    }
                } else {
                    if (entryRes && departRes && updateRes) {
                        ygDdJgMap.put(ygTemp, "0");
                    } else {
                        ygDdJgMap.put(ygTemp, "1");
                    }
                }
            }

            baseBean.writeLog("generateIndexDt sxGwMap is:" + sxGwMap);
            baseBean.writeLog("generateIndexDt sxZtMap is:" + sxZtMap);
            baseBean.writeLog("generateIndexDt sxBmMap is:" + sxBmMap);
            baseBean.writeLog("generateIndexDt sxZjMap is:" + sxZjMap);
            baseBean.writeLog("generateIndexDt ygDdJgMap is:" + ygDdJgMap);
            baseBean.writeLog("generateIndexDt sxFbMap is:" + sxFbMap);

            // 获取分部对应的所有上级分部
            Map<String, String> fbAndSupMap = new HashMap<>();
            rs.execute("SELECT id, supsubcomid FROM hrmsubcompany WHERE canceled != 1 or canceled is null");
            while (rs.next()) {
                String fbId = rs.getString("id");
                if (StringUtils.isEmpty(fbId)) {
                    continue;
                }
                String supsubcomid = rs.getString("supsubcomid");
                fbAndSupMap.put(fbId, supsubcomid);
            }
            Map<String, Set<String>> fbAndXjListMap = new HashMap<>();
            for (Map.Entry<String, String> entry : fbAndSupMap.entrySet()) {
                String key = entry.getKey();
                String value = entry.getValue();
                if (StringUtils.isNotEmpty(key)) {
                    Set<String> tempSet = new HashSet<>();
                    if ((!CollectionUtils.isEmpty(fbAndXjListMap)) && fbAndXjListMap.containsKey(key)) {
                        tempSet = fbAndXjListMap.get(key);
                    }
                    tempSet.add(key);
                    fbAndXjListMap.put(key, tempSet);
                }
                if (StringUtils.isNotEmpty(value)) {
                    Set<String> tempSet = new HashSet<>();
                    if ((!CollectionUtils.isEmpty(fbAndXjListMap)) && fbAndXjListMap.containsKey(value)) {
                        tempSet = fbAndXjListMap.get(value);
                    }
                    tempSet.add(value);
                    tempSet.add(key);
                    fbAndXjListMap.put(value, tempSet);
                }
            }
            baseBean.writeLog("generateIndexDt fbAndXjListMap is:" + fbAndXjListMap);

            // 获取工号与id对应
            Map<String, String> idAndGhMap = new HashMap<>();
            rs.execute("SELECT id, workcode FROM hrmresource WHERE workcode is not null");
            while (rs.next()) {
                String id = rs.getString("id");
                String workcode = rs.getString("workcode");
                if (StringUtils.isEmpty(id) || StringUtils.isEmpty(workcode)) {
                    continue;
                }
                idAndGhMap.put(id, workcode);
            }

            // 获取二级指标相关信息
            Map<String, String> ejzbMap = new HashMap<>();
            Map<String, String> ejzbszfbMap = new HashMap<>();
            rs.execute("SELECT id, xjzb, ejzbszfb FROM uf_zbk");
            while (rs.next()) {
                String id = rs.getString("id");
                if (StringUtils.isEmpty(id)) {
                    continue;
                }
                String xjzb = rs.getString("xjzb");
                String ejzbszfb = rs.getString("ejzbszfb");
                ejzbMap.put(id, xjzb);
                ejzbszfbMap.put(id, ejzbszfb);
            }

            Map<String, Map<String, String>> rysxMap = new HashMap<>();
            rs.execute("SELECT * FROM uf_rysxtj");
            while (rs.next()) {
                String id = rs.getString("id");
                String szfbbhxj = rs.getString("szfbbhxj");
                String ygzt = rs.getString("ygzt");
                String gw = rs.getString("gw");
                String bm = rs.getString("bm");
                String jtry = rs.getString("jtry");
                String gwxl = rs.getString("gwxl");
                String sfbmtdfzr = rs.getString("sfbmtdfzr");
                String rylb = rs.getString("rylb");
                String zj = rs.getString("zj");
                String rzkssj = rs.getString("rzkssj");
                String rzjssj = rs.getString("rzjssj");
                String gwbdsxkssj = rs.getString("gwbdsxkssj");
                String gwbdsxsjjs = rs.getString("gwbdsxsjjs");
                String lzkssj = rs.getString("lzkssj");
                String lzjssj = rs.getString("lzjssj");
                String rzts = rs.getString("rzts");
                String zxgwbdsxts = rs.getString("zxgwbdsxts");
                String sfbhq = rs.getString("sfbhq");
                String xxbmtd = rs.getString("xxbmtd");
                String ryzxmc = rs.getString("ryzxmc");
                String gwmc = rs.getString("gwmc");
                String zjx = rs.getString("zjx");

                Map<String, String> rysxMapTemp = new HashMap<>();
                rysxMapTemp.put("szfbbhxj", szfbbhxj);
                rysxMapTemp.put("ygzt", ygzt);
                rysxMapTemp.put("gw", gw);
                rysxMapTemp.put("bm", bm);
                rysxMapTemp.put("jtry", jtry);
                rysxMapTemp.put("gwxl", gwxl);
                rysxMapTemp.put("sfbmtdfzr", sfbmtdfzr);
                rysxMapTemp.put("rylb", rylb);
                rysxMapTemp.put("zj", zj);
                rysxMapTemp.put("rzkssj", rzkssj);
                rysxMapTemp.put("rzjssj", rzjssj);
                rysxMapTemp.put("gwbdsxkssj", gwbdsxkssj);
                rysxMapTemp.put("gwbdsxsjjs", gwbdsxsjjs);
                rysxMapTemp.put("lzkssj", lzkssj);
                rysxMapTemp.put("lzjssj", lzjssj);
                rysxMapTemp.put("rzts", rzts);
                rysxMapTemp.put("zxgwbdsxts", zxgwbdsxts);
                rysxMapTemp.put("sfbhq", sfbhq);
                rysxMapTemp.put("xxbmtd", xxbmtd);
                rysxMapTemp.put("ryzxmc", ryzxmc);
                rysxMapTemp.put("gwmc", gwmc);
                rysxMapTemp.put("zjx", zjx);

                rysxMap.put(id, rysxMapTemp);
            }

            // 考虑从导入表中取“指标权重”值
            Map<String, String> zbqzMap = new HashMap<>();
            rs.execute("SELECT * FROM uf_jyzdr");
            while (rs.next()) {
                String ygDr = rs.getString("yg");
                String szkhjhDr = rs.getString("szkhjh");
                String szkhfaDr = rs.getString("szkhfa");
                String dyzbDr = rs.getString("dyzb");
                String zbqzDr = rs.getString("zbqz");
                if (StringUtils.isEmpty(ygDr) || StringUtils.isEmpty(szkhjhDr) || StringUtils.isEmpty(szkhfaDr) || StringUtils.isEmpty(dyzbDr)) {
                    continue;
                }
                zbqzMap.put(ygDr + "_" + szkhjhDr + "_" + szkhfaDr + "_" + dyzbDr, zbqzDr);
            }

            RecordSet rs1 = new RecordSet();
            /*String querySql = "select t1.*,t2.gw,t2.szfbbhxj,t2.gwmc,t2.bm,t2.jtry,t2.gwxl,t2.sfbmtdfzr,t2.rylb,t2.zj,t2.zjx,t2.rzkssj,t2.rzjssj," +
                    " t2.gwbdsxkssj,t2.gwbdsxsjjs,t2.lzkssj,t2.lzjssj,t2.rzts,t2.zxgwbdsxts,t2.sfbhq,t2.xxbmtd,t2.ygzt FROM (\n" +
                    " select a.*, b.sfscbzjxxs,b.khfabm,b.khfamc,b.khfalx,b.khyylx,b.szfs,b.szzw,b.khdxbdljid,b.yxj,b.id as dataId  \n" +
                    " from uf_bzkhfa_dt1 a, uf_bzkhfa b where a.mainid = b.id and b.id in (" + khfas + ")\n" +
                    ") t1 \n" +
                    " LEFT JOIN uf_rysxtj t2 ON t1.khdxbdljid = t2.id";*/
            String querySql = "select a.*, b.sfscbzjxxs,b.khfabm,b.khfamc,b.khfalx,b.khyylx,b.szfs,b.szzw,b.khdxbdljid,b.yxj,b.id as dataId  \n" +
                    " from uf_bzkhfa_dt1 a, uf_bzkhfa b where a.mainid = b.id and b.id in (" + khfas + ")";
            rs.execute(querySql);
            Map<String, Map<String, String>> faMainInfoMap = new HashMap<>();
            Map<String, List<Map<String, String>>> faDtInfoMap = new HashMap<>();

            Map<String, String> sfScMap = new HashMap<>();

            Map<String, String> ryMap = new HashMap<>();
            while (rs.next()) {
                String id = rs.getString("id");
                String zbid = rs.getString("zbid");
                String zbmc = rs.getString("zbmc");
                String zbms = rs.getString("zbms");
                String zbqz = rs.getString("zbqz");
                String jyzycgzid = rs.getString("jyzycgzid");
                String jfgzid = rs.getString("jfgzid");
                String jckfxs = rs.getString("jckfxs");

                String x1 = rs.getString("x1");
                String x2 = rs.getString("x2");
                String x3 = rs.getString("x3");
                String x4 = rs.getString("x4");
                String x5 = rs.getString("x5");

                String n1 = rs.getString("n1");
                String n2 = rs.getString("n2");
                String n3 = rs.getString("n3");
                String n4 = rs.getString("n4");
                String n5 = rs.getString("n5");
                String n6 = rs.getString("n6");

                String sfscbzjxxs = rs.getString("sfscbzjxxs");
                if (StringUtils.isEmpty(sfscbzjxxs)) {
                    sfscbzjxxs = "0";
                }

                String khdxbdljid = rs.getString("khdxbdljid");
                if (StringUtils.isEmpty(khdxbdljid)) {
                    continue;
                }

                String dataId = rs.getString("dataId");
                List<Map<String, String>> mapList = new ArrayList<>();
                if ((!CollectionUtils.isEmpty(faDtInfoMap)) && faDtInfoMap.containsKey(dataId)) {
                    mapList = faDtInfoMap.get(dataId);
                }

                sfScMap.put(dataId, sfscbzjxxs);

                Map<String, String> dtMap = new HashMap<>();
                dtMap.put("zbid", zbid);
                dtMap.put("zbmc", zbmc);
                dtMap.put("zbms", zbms);
                dtMap.put("zbqz", zbqz);
                dtMap.put("jyzycgzid", jyzycgzid);
                dtMap.put("jfgzid", jfgzid);
                dtMap.put("jckfxs", jckfxs);

                dtMap.put("x1", x1);
                dtMap.put("x2", x2);
                dtMap.put("x3", x3);
                dtMap.put("x4", x4);
                dtMap.put("x5", x5);
                dtMap.put("n1", n1);
                dtMap.put("n2", n2);
                dtMap.put("n3", n3);
                dtMap.put("n4", n4);
                dtMap.put("n5", n5);
                dtMap.put("n6", n6);

                mapList.add(dtMap);
                faDtInfoMap.put(dataId, mapList);

                if ((!CollectionUtils.isEmpty(faMainInfoMap)) && faMainInfoMap.containsKey(dataId)) {
                    continue;
                }

                String khfabm = rs.getString("khfabm");
                String khfamc = rs.getString("khfamc");
                String khfalx = rs.getString("khfalx");
                String khyylx = rs.getString("khyylx");
                String szfs = rs.getString("szfs");
                String szzw = rs.getString("szzw");
                String yxj = rs.getString("yxj");
                if (StringUtils.isEmpty(yxj)) {
                    yxj = "0";
                }
                Map<String, String> mainMap = new HashMap<>();
                mainMap.put("khfabm", khfabm);
                mainMap.put("khfamc", khfamc);
                mainMap.put("khfalx", khfalx);
                mainMap.put("khyylx", khyylx);
                mainMap.put("szfs", szfs);
                mainMap.put("szzw", szzw);
                mainMap.put("khdxbdljid", khdxbdljid);
                mainMap.put("yxj", yxj);
                faMainInfoMap.put(dataId, mainMap);

                Set<String> rySet = new HashSet<>();

                String[] khdxbdljidArr = khdxbdljid.split(",");
                for (String khdxbdljidTemp : khdxbdljidArr) {
                    Map<String, String> rysxTemp = rysxMap.get(khdxbdljidTemp);
                    if (CollectionUtils.isEmpty(rysxTemp)) {
                        continue;
                    }
                    String sqlA = "SELECT a.id,a.companystartdate,a.enddate,b." + gwFieldId + " as gw, a.subcompanyid1, b." + zjFieldId + " as zj FROM hrmresource a " +
                            " LEFT JOIN cus_fielddata b ON a.id = b.id and b.scope = 'HrmCustomFieldByInfoType' and scopeid = 3 " +
                            " WHERE 1 = 1 ";

                    String ygzt = rysxTemp.get("ygzt");
//                if (StringUtils.isNotEmpty(ygzt)) {
//                    sqlA = sqlA + " and a.status in (" + ygzt + ") ";
//                }
                    String bm = rysxTemp.get("bm");
//                if (StringUtils.isNotEmpty(bm)) {
//                    sqlA = sqlA + " and a.departmentid in (" + bm + ") ";
//                }
//                String jtry = rs.getString("jtry");
//                if (StringUtils.isNotEmpty(jtry)) {
//                    sqlA = sqlA + " and a.id in (" + jtry + ") ";
//                }
                    String sfbmtdfzr = rysxTemp.get("sfbmtdfzr");
                    Set<String> rySetA = new HashSet<>();
                    if (StringUtils.isNotEmpty(sfbmtdfzr) && StringUtils.equals(sfbmtdfzr, "0")) {
                        rs1.execute("SELECT bmfgld FROM hrmdepartment WHERE bmfgld is not null and (canceled is null or canceled != 1)");
                        while (rs1.next()) {
                            String bmfzrT = rs1.getString("bmfgld");
                            if (StringUtils.isEmpty(bmfzrT)) {
                                continue;
                            }
                            rySetA.addAll(Arrays.asList(bmfzrT.split(",")));
                        }
                        if (!CollectionUtils.isEmpty(rySetA)) {
                            sqlA = sqlA + " and a.id in (" + String.join(",", rySetA) + ") ";
                        }
                    }

                    String rylb = rysxTemp.get("rylb");
//                if (StringUtils.isNotEmpty(rylb)) {
//                    sqlA = sqlA + " and a.usekind in (" + rylb + ") ";
//                }

                    String rzkssj = rysxTemp.get("rzkssj");
                    String rzkssjT = "";
                    if (StringUtils.isNotEmpty(rzkssj) && ((new BigDecimal(rzkssj).compareTo(new BigDecimal("1")) >= 0
                            && new BigDecimal(rzkssj).compareTo(new BigDecimal(String.valueOf(lastDay))) <= 0) || new BigDecimal(rzkssj).compareTo(new BigDecimal("99")) == 0)) {
                        if (new BigDecimal(rzkssj).compareTo(new BigDecimal("99")) == 0) {
                            rzkssjT = yearMonth.atDay(lastDay).toString();
                        } else {
                            rzkssjT = yearMonth.atDay(Integer.parseInt(rzkssj)).toString();
                        }
//                    sqlA = sqlA + " and a.companystartdate >= '" + rzkssjT + "' ";
                    }
                    String rzjssj = rysxTemp.get("rzjssj");
                    String rzjssjT = "";
                    if (StringUtils.isNotEmpty(rzjssj) && ((new BigDecimal(rzjssj).compareTo(new BigDecimal("1")) >= 0
                            && new BigDecimal(rzjssj).compareTo(new BigDecimal(String.valueOf(lastDay))) <= 0) || new BigDecimal(rzjssj).compareTo(new BigDecimal("99")) == 0)) {
                        if (new BigDecimal(rzjssj).compareTo(new BigDecimal("99")) == 0) {
                            rzjssjT = yearMonth.atDay(lastDay).toString();
                        } else {
                            rzjssjT = yearMonth.atDay(Integer.parseInt(rzjssj)).toString();
                        }
//                    sqlA = sqlA + " and a.companystartdate <= '" + rzjssjT + "' ";
                    }

                    String lzkssj = rysxTemp.get("lzkssj");
                    String lzkssjT = "";
                    if (StringUtils.isNotEmpty(lzkssj) && ((new BigDecimal(lzkssj).compareTo(new BigDecimal("1")) >= 0
                            && new BigDecimal(lzkssj).compareTo(new BigDecimal(String.valueOf(lastDay))) <= 0) || new BigDecimal(lzkssj).compareTo(new BigDecimal("99")) == 0)) {
                        if (new BigDecimal(lzkssj).compareTo(new BigDecimal("99")) == 0) {
                            lzkssjT = yearMonth.atDay(lastDay).toString();
                        } else {
                            lzkssjT = yearMonth.atDay(Integer.parseInt(lzkssj)).toString();
                        }
//                    sqlA = sqlA + " and a.enddate >= '" + lzkssjT + "' ";
                    }
                    String lzjssj = rysxTemp.get("lzjssj");
                    String lzjssjT = null;
                    if (StringUtils.isNotEmpty(lzjssj) && ((new BigDecimal(lzjssj).compareTo(new BigDecimal("1")) >= 0
                            && new BigDecimal(lzjssj).compareTo(new BigDecimal(String.valueOf(lastDay))) <= 0) || new BigDecimal(lzjssj).compareTo(new BigDecimal("99")) == 0)) {
                        if (new BigDecimal(lzjssj).compareTo(new BigDecimal("99")) == 0) {
                            lzjssjT = yearMonth.atDay(lastDay).toString();
                        } else {
                            lzjssjT = yearMonth.atDay(Integer.parseInt(lzjssj)).toString();
                        }
//                    sqlA = sqlA + " and a.enddate <= '" + lzjssjT + "' ";
                    }
                    String rzts = rysxTemp.get("rzts");
                    if (StringUtils.isNotEmpty(rzts) && !StringUtils.equals(rzts, "0")) {
                        LocalDate previousDate = currentDate.minusDays(Integer.parseInt(rzts));
                        sqlA = sqlA + " and a.companystartdate >= '" + previousDate + "' ";
                    }

                    String xxbmtd = rysxTemp.get("xxbmtd");
                    Set<String> rySetB = new HashSet<>();
                    if (StringUtils.isNotEmpty(xxbmtd) && (!StringUtils.equals(xxbmtd, "0")) && (!CollectionUtils.isEmpty(bmCntMap))) {
                        for (Map.Entry<String, Integer> entry : bmCntMap.entrySet()) {
                            String key = entry.getKey();
                            Integer value = entry.getValue();
                            if (value == Integer.parseInt(xxbmtd)) {
                                rySetB.add(key);
                            }
                        }
                        if (!CollectionUtils.isEmpty(rySetB)) {
                            sqlA = sqlA + " and a.id in (" + String.join(",", rySetB) + ") ";
                        }
                    }

                    String sfbhq = rysxTemp.get("sfbhq");
//                if (StringUtils.isNotEmpty(sfbhq) && StringUtils.equals(sfbhq, "0")) {
//                    rs1.execute("SELECT ygxm FROM uf_khbhqxxrg  where lx = 1");
//                    while (rs1.next()) {
//                        String idT = rs1.getString("ygxm");
//                        if (StringUtils.isEmpty(idT)) {
//                            continue;
//                        }
//                        rySet.add(idT);
//                    }
//                }

                    Set<String> gwSet = new HashSet<>();
                    String zwxl = rysxTemp.get("gwxl");
                    if (StringUtils.isNotEmpty(zwxl)) {
                        String xl = "P";
                        if (StringUtils.equals(zwxl, "1")) {
                            xl = "M";
                        }
                        rs1.executeQuery("select id from uf_JCL_GWGL where szzwxl in (select id from uf_zwxl where xlbm = ?)", xl);
                        while (rs1.next()) {
                            String idT = rs1.getString("id");
                            if (StringUtils.isEmpty(idT)) {
                                continue;
                            }
                            gwSet.add(idT);
                        }
                    }

                    String gwbdsxkssj = rysxTemp.get("gwbdsxkssj");
                    String gwbdsxsjjs = rysxTemp.get("gwbdsxsjjs");
                    String zxgwbdsxts = rysxTemp.get("zxgwbdsxts");

                    String gw = rysxTemp.get("gw");
                    String gwmc = rysxTemp.get("gwmc");
                    Set<String> gwmcSet = new HashSet<>();
                    if (StringUtils.isNotEmpty(gwmc)) {
                        String[] gwmcArr = gwmc.split("；");
                        String gwmcSql = "SELECT id FROM uf_JCL_GWGL ";
                        for (int i = 0; i < gwmcArr.length; i++) {
                            if (i == 0) {
                                gwmcSql = gwmcSql + " WHERE gwmc LIKE '%" + gwmcArr[i] + "%' ";
                            } else {
                                gwmcSql = gwmcSql + " OR gwmc LIKE '%" + gwmcArr[i] + "%' ";
                            }
                        }
                        baseBean.writeLog("generateIndexDt gwmcSql:" + gwmcSql);
                        rs1.execute(gwmcSql);
                        while (rs1.next()) {
                            String dataIdT = rs1.getString("id");
                            if (StringUtils.isNotEmpty(dataIdT)) {
                                gwmcSet.add(dataIdT);
                            }
                        }
                    }
                    String zj = rysxTemp.get("zj");
                    String zjx = rysxTemp.get("zjx");
                    String szfbbhxj = rysxTemp.get("szfbbhxj");

                    if (StringUtils.isEmpty(ygzt) && StringUtils.isEmpty(bm) && StringUtils.isEmpty(szfbbhxj) && (StringUtils.isEmpty(sfbmtdfzr) || StringUtils.equals(sfbmtdfzr, "1"))
                            && StringUtils.isEmpty(rylb) && StringUtils.isEmpty(rzkssj) && StringUtils.isEmpty(rzjssj) && StringUtils.isEmpty(lzkssj)
                            && StringUtils.isEmpty(lzjssj) && StringUtils.isEmpty(rzts) && StringUtils.isEmpty(xxbmtd)
                            && StringUtils.isEmpty(sfbhq) && StringUtils.isEmpty(zwxl) && StringUtils.isEmpty(gwmc) && StringUtils.isEmpty(gw) && StringUtils.isEmpty(zj) && StringUtils.isEmpty(zjx)) {
                        sqlA = sqlA + " AND 1=2 ";
                    }
                    baseBean.writeLog("generateIndexDt gwmcSet:" + gwmcSet);
                    baseBean.writeLog("generateIndexDt sqlA:" + sqlA);
                    rs1.execute(sqlA);
                    while (rs1.next()) {
                        String idT = rs1.getString("id");
                        String gwT = rs1.getString("gw");
                        String zjT = rs1.getString("zj");
                        String companystartdateT = rs1.getString("companystartdate");
                        String enddateT = rs1.getString("enddate");
//                    if (StringUtils.isNotEmpty(gw)) {
//                        if (StringUtils.isEmpty(gwT)) {
//                            continue;
//                        }
//                        List<String> list = Arrays.asList(gw.split(","));
//                        if (!list.contains(gwT)) {
//                            continue;
//                        }
//                    }
                        boolean rzRes = true;
                        if (StringUtils.isNotEmpty(rzkssjT) && StringUtils.isNotEmpty(rzjssjT)) {
                            if (StringUtils.isEmpty(companystartdateT)) {
                                rzRes = false;
                            } else {
                                LocalDate rzkssjTLd = LocalDate.parse(rzkssjT, formatterRq);
                                LocalDate rzjssjTLd = LocalDate.parse(rzjssjT, formatterRq);
                                LocalDate companystartdateTLd = LocalDate.parse(companystartdateT, formatterRq);
                                if ((!companystartdateTLd.isBefore(rzkssjTLd)) && (!companystartdateTLd.isAfter(rzjssjTLd))) {
                                    rzRes = true;
                                } else {
                                    rzRes = false;
                                }
                            }
                        } else if (StringUtils.isEmpty(rzkssjT) && StringUtils.isNotEmpty(rzjssjT)) {
                            if (StringUtils.isEmpty(companystartdateT)) {
                                rzRes = false;
                            } else {
                                LocalDate rzjssjTLd = LocalDate.parse(rzjssjT, formatterRq);
                                LocalDate companystartdateTLd = LocalDate.parse(companystartdateT, formatterRq);
                                if (!companystartdateTLd.isAfter(rzjssjTLd)) {
                                    rzRes = true;
                                } else {
                                    rzRes = false;
                                }
                            }
                        } else if (StringUtils.isNotEmpty(rzkssjT) && StringUtils.isEmpty(rzjssjT)) {
                            if (StringUtils.isEmpty(companystartdateT)) {
                                rzRes = false;
                            } else {
                                LocalDate rzkssjTLd = LocalDate.parse(rzkssjT, formatterRq);
                                LocalDate companystartdateTLd = LocalDate.parse(companystartdateT, formatterRq);
                                if (!companystartdateTLd.isBefore(rzkssjTLd)) {
                                    rzRes = true;
                                } else {
                                    rzRes = false;
                                }
                            }
                        }
                        boolean lzRes = true;
                        if (StringUtils.isNotEmpty(lzkssjT) && StringUtils.isNotEmpty(lzjssjT)) {
                            if (StringUtils.isEmpty(enddateT)) {
                                lzRes = false;
                            } else {
                                LocalDate lzkssjTLd = LocalDate.parse(lzkssjT, formatterRq);
                                LocalDate lzjssjTLd = LocalDate.parse(lzjssjT, formatterRq);
                                LocalDate enddateTLd = LocalDate.parse(enddateT, formatterRq);
                                if ((!enddateTLd.isBefore(lzkssjTLd)) && (!enddateTLd.isAfter(lzjssjTLd))) {
                                    lzRes = true;
                                } else {
                                    lzRes = false;
                                }
                            }
                        } else if (StringUtils.isEmpty(lzkssjT) && StringUtils.isNotEmpty(lzjssjT)) {
                            if (StringUtils.isEmpty(enddateT)) {
                                lzRes = false;
                            } else {
                                LocalDate lzjssjTLd = LocalDate.parse(lzjssjT, formatterRq);
                                LocalDate enddateTLd = LocalDate.parse(enddateT, formatterRq);
                                if (!enddateTLd.isAfter(lzjssjTLd)) {
                                    lzRes = true;
                                } else {
                                    lzRes = false;
                                }
                            }
                        } else if (StringUtils.isNotEmpty(lzkssjT) && StringUtils.isEmpty(lzjssjT)) {
                            if (StringUtils.isEmpty(enddateT)) {
                                lzRes = false;
                            } else {
                                LocalDate lzkssjTLd = LocalDate.parse(lzkssjT, formatterRq);
                                LocalDate enddateTLd = LocalDate.parse(enddateT, formatterRq);
                                if (!enddateTLd.isBefore(lzkssjTLd)) {
                                    lzRes = true;
                                } else {
                                    lzRes = false;
                                }
                            }
                        }

                        if (StringUtils.isNotEmpty(bm)) {
                            String pdBm = sxBmMap.get(idT);
                            if (StringUtils.isEmpty(pdBm)) {
                                continue;
                            }
                            List<String> bmList = Arrays.asList(bm.split(","));
                            if (CollectionUtils.isEmpty(bmList) || !bmList.contains(pdBm)) {
                                continue;
                            }
                            String sfmztj = ygDdJgMap.get(idT);
                            if (StringUtils.isEmpty(sfmztj) || !StringUtils.equals(sfmztj, "0")) {
                                continue;
                            }
                        }

                        if (StringUtils.isNotEmpty(szfbbhxj)) {
                            String pdFb = sxFbMap.get(idT);
                            if (StringUtils.isEmpty(pdFb)) {
                                continue;
                            }
                            String[] szfbbhxjArr = szfbbhxj.split(",");
                            boolean isHave = false;
                            for (String szfbbhxjTemp : szfbbhxjArr) {
                                Set<String> szfbbhxjSetTemp = fbAndXjListMap.get(szfbbhxjTemp);
                                if ((!CollectionUtils.isEmpty(szfbbhxjSetTemp)) && szfbbhxjSetTemp.contains(pdFb)) {
                                    isHave = true;
                                    break;
                                }
                            }
                            if (!isHave) {
                                continue;
                            }
                        }
                        if (StringUtils.isNotEmpty(gwmc)) {
                            String pdGw = sxGwMap.get(idT);
                            if (StringUtils.isEmpty(pdGw)) {
                                continue;
                            }
                            if (CollectionUtils.isEmpty(gwmcSet) || !gwmcSet.contains(pdGw)) {
                                continue;
                            }
                            String sfmztj = ygDdJgMap.get(idT);
                            if (StringUtils.isEmpty(sfmztj) || !StringUtils.equals(sfmztj, "0")) {
                                continue;
                            }
                        }
                        if (StringUtils.isNotEmpty(zwxl)) {
                            String pdGw = sxGwMap.get(idT);
                            if (StringUtils.isEmpty(pdGw)) {
                                continue;
                            }
                            if (CollectionUtils.isEmpty(gwSet) || !gwSet.contains(pdGw)) {
                                continue;
                            }
                            String sfmztj = ygDdJgMap.get(idT);
                            if (StringUtils.isEmpty(sfmztj) || !StringUtils.equals(sfmztj, "0")) {
                                continue;
                            }
                        }
                        if (StringUtils.isNotEmpty(zj)) {
                            String pdZj = sxZjMap.get(idT);
                            if (StringUtils.isEmpty(pdZj)) {
                                continue;
                            }
                            List<String> list = Arrays.asList(zj.split(","));
                            if (!list.contains(pdZj)) {
                                continue;
                            }
                            String sfmztj = ygDdJgMap.get(idT);
                            if (StringUtils.isEmpty(sfmztj) || !StringUtils.equals(sfmztj, "0")) {
                                continue;
                            }
                        }
                        if (StringUtils.isNotEmpty(ygzt)) {
                            String pdZt = sxZtMap.get(idT);
                            if (StringUtils.isEmpty(pdZt) || !StringUtils.equals(pdZt, ygzt)) {
                                continue;
                            }
                            String sfmztj = ygDdJgMap.get(idT);
                            if (StringUtils.isEmpty(sfmztj) || !StringUtils.equals(sfmztj, "0")) {
                                continue;
                            }
                        }
                        if (StringUtils.isNotEmpty(rylb)) {
                            String pdYgxz = sxYgxzMap.get(idT);
                            if (StringUtils.isEmpty(pdYgxz) || !StringUtils.equals(pdYgxz, rylb)) {
                                continue;
                            }
                            String sfmztj = ygDdJgMap.get(idT);
                            if (StringUtils.isEmpty(sfmztj) || !StringUtils.equals(sfmztj, "0")) {
                                continue;
                            }
                        }
                        if (StringUtils.isNotEmpty(zjx)) {
                            String pdZj = sxZjMap.get(idT);
                            if (StringUtils.isEmpty(pdZj)) {
                                continue;
                            }
                            List<String> list = Arrays.asList(zjx.split(","));
                            if (!list.contains(pdZj)) {
                                continue;
                            }
                            String sfmztj = ygDdJgMap.get(idT);
                            if (StringUtils.isEmpty(sfmztj) || !StringUtils.equals(sfmztj, "0")) {
                                continue;
                            }
                        }
                        if (StringUtils.equals(sfbhq, "0")) {
                            if (CollectionUtils.isEmpty(protectSet) || !protectSet.contains(idT)) {
                                continue;
                            }
                        }
                        if (StringUtils.equals(sfbhq, "1")) {
                            if ((!CollectionUtils.isEmpty(protectSet)) && protectSet.contains(idT)) {
                                continue;
                            }
                        }

                        boolean gwbdARes = true;
                        boolean gwbdBRes = true;
                        if (StringUtils.isNotEmpty(gwbdsxkssj) && ((new BigDecimal(gwbdsxkssj).compareTo(new BigDecimal("1")) >= 0
                                && new BigDecimal(gwbdsxkssj).compareTo(new BigDecimal(String.valueOf(lastDay))) <= 0) || new BigDecimal(gwbdsxkssj).compareTo(new BigDecimal("99")) == 0)) {
                            String ddrqTemp = ddrqMap.get(idT);
                            if (StringUtils.isEmpty(ddrqTemp)) {
                                gwbdARes = false;
                            } else {
                                String rqTemp = "";
                                if (new BigDecimal(gwbdsxkssj).compareTo(new BigDecimal("99")) == 0) {
                                    rqTemp = yearMonth.atDay(lastDay).toString();
                                } else {
                                    rqTemp = yearMonth.atDay(Integer.parseInt(gwbdsxkssj)).toString();
                                }
                                if (LocalDate.parse(ddrqTemp, formatterRq).isBefore(LocalDate.parse(rqTemp, formatterRq))) {
                                    gwbdARes = false;
                                }
                            }
                        }

                        if (StringUtils.isNotEmpty(gwbdsxsjjs) && ((new BigDecimal(gwbdsxsjjs).compareTo(new BigDecimal("1")) >= 0
                                && new BigDecimal(gwbdsxsjjs).compareTo(new BigDecimal(String.valueOf(lastDay))) <= 0) || new BigDecimal(gwbdsxsjjs).compareTo(new BigDecimal("99")) == 0)) {
                            String ddrqTemp = ddrqMap.get(idT);
                            if (StringUtils.isEmpty(ddrqTemp)) {
                                gwbdBRes = false;
                            } else {
                                String rqTemp = "";
                                if (new BigDecimal(gwbdsxsjjs).compareTo(new BigDecimal("99")) == 0) {
                                    rqTemp = yearMonth.atDay(lastDay).toString();
                                } else {
                                    rqTemp = yearMonth.atDay(Integer.parseInt(gwbdsxsjjs)).toString();
                                }
                                if (!LocalDate.parse(ddrqTemp, formatterRq).isBefore(LocalDate.parse(rqTemp, formatterRq))) {
                                    gwbdBRes = false;
                                }
                            }
                        }
                        boolean gwbdRes = gwbdBRes && gwbdARes;
                        if (gwbdRes || rzRes || lzRes) {

                        } else {
                            continue;
                        }

                        if (StringUtils.isNotEmpty(zxgwbdsxts)) {
                            String ddrqTemp = ddrqMap.get(idT);
                            if (StringUtils.isEmpty(ddrqTemp)) {
                                continue;
                            }
                            long daysBetween = ChronoUnit.DAYS.between(LocalDate.parse(ddrqTemp, formatterRq), LocalDate.parse(jhksrq, formatterRq));
                            if (daysBetween < 0) {
                                daysBetween = -daysBetween;
                            }
                            if (new BigDecimal(String.valueOf(daysBetween)).compareTo(new BigDecimal(zxgwbdsxts)) <= 0) {
                                continue;
                            }
                        }
                        rySet.add(idT);
                    }
                    String jtry = rysxTemp.get("jtry");
                    if (StringUtils.isNotEmpty(jtry)) {
                        rySet.addAll(Arrays.asList(jtry.split(",")));
                    }
                }

                if (CollectionUtils.isEmpty(rySet)) {
                    continue;
                }
                baseBean.writeLog("rySet size:" + rySet.size());
                for (String ry : rySet) {
                    if ((!CollectionUtils.isEmpty(ryMap)) && ryMap.containsKey(ry)) {
                        String s = ryMap.get(ry);
                        String faId = s.split("_")[0];
                        String yxjTemp = s.split("_")[1];
                        if (new BigDecimal(yxjTemp).compareTo(new BigDecimal(yxj)) > 0) {
                            ryMap.put(ry, dataId + "_" + yxj);
                        }
                        continue;
                    }
                    ryMap.put(ry, dataId + "_" + yxj);
                }
            }

            if (CollectionUtils.isEmpty(ryMap)) {
                baseBean.writeLog("ryMap is null.");
                result.put("mes", "未查到需生成指标的员工，请检查！");
                result.put("code", "200");
                return result;
            }
            baseBean.writeLog("ryMap size is:" + ryMap.size());
            String insertSql = "INSERT INTO uf_ygmxzbdy (yg, yggh,szfs, szbm, szgw, szkhjh, szkhfa, sfscbzjxxs, formmodeid, MODEUUID, " +
                    "modedatacreater,modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            String insertDtSql = "insert into uf_ygmxzbdy_dt1 (mainid,zbid,zbmc,zbms,zbqz,jyzycgzid,jfgzid,jckfxs,x1,x2,x3," +
                    "x4,x5,n1,n2,n3,n4,n5,n6) " +
                    "values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
            // 员工明细指标建模id
            String modeId = rs.getPropValue("qz_jx_zm_prop", "ygmxzb_mode_id");
            // 员工明细指标查询id
            String cusId = rs.getPropValue("qz_jx_zm_prop", "ygmxzb_cus_id");
            for (Map.Entry<String, String> ryEntry : ryMap.entrySet()) {
                String key = ryEntry.getKey();
                if (StringUtils.equals(key, "1")) {
                    continue;
                }
                String yggh = idAndGhMap.get(key);
                if (StringUtils.isEmpty(yggh)) {
                    yggh = "0";
                }
                String value = ryEntry.getValue();
                String faId = value.split("_")[0];
                String uuid = UUID.randomUUID() + "-" + key;
                String sfSc = sfScMap.get(faId);
                if (StringUtils.isEmpty(sfSc)) {
                    sfSc = "0";
                }
                String szfbTemp = fbMap.get(key);
                rs.executeUpdate(insertSql, key, yggh, szfbTemp, bmMap.get(key), gwMap.get(key), khjh, faId, sfSc, modeId, uuid, "1",
                        "0", sdfDate.format(new Date()), sdfTime.format(new Date()));
                List<Map<String, String>> mapList = faDtInfoMap.get(faId);
                if (CollectionUtils.isEmpty(mapList)) {
                    continue;
                }
                int dataId = 0;
                rs.executeQuery("SELECT id FROM uf_ygmxzbdy WHERE MODEUUID = ?", uuid);
                if (rs.next()) {
                    dataId = rs.getInt("id");
                }
                if (dataId > 0) {
                    List<List> insertParams = new ArrayList<>();
                    for (Map<String, String> map : mapList) {
                        List insertParam = new ArrayList<>();
                        insertParam.add(dataId);
                        String zbid = map.get("zbid");
                        if (StringUtils.isEmpty(zbid)) {
                            continue;
                        }
                        String zbidNew = zbid;
                        String xjzb = ejzbMap.get(zbid);
                        if (StringUtils.isNotEmpty(xjzb)) {
                            String[] xjzbArr = xjzb.split(",");
                            for (String xjzbTemp : xjzbArr) {
                                if (StringUtils.equals(szfbTemp, ejzbszfbMap.get(xjzbTemp))) {
                                    zbidNew = xjzbTemp;
                                    break;
                                }
                            }
                        }
                        if (StringUtils.isEmpty(zbidNew)) {
                            continue;
                        }

                        insertParam.add(Integer.parseInt(zbidNew));
                        insertParam.add(Util.null2String(map.get("zbmc")));
                        insertParam.add(Util.null2String(map.get("zbms")));
                        String zbqzInsert = map.get("zbqz");
                        // 考虑从导入表中取值
                        if ((!CollectionUtils.isEmpty(zbqzMap)) && zbqzMap.containsKey(key + "_" + khjh + "_" + faId + "_" + zbidNew)) {
                            zbqzInsert = zbqzMap.get(key + "_" + khjh + "_" + faId + "_" + zbidNew);
                        }
                        if (StringUtils.isEmpty(zbqzInsert)) {
                            zbqzInsert = "0";
                        }
                        insertParam.add(zbqzInsert);
                        String jyzycgzidS = map.get("jyzycgzid");
                        if (StringUtils.isEmpty(jyzycgzidS)) {
                            jyzycgzidS = "0";
                        }
                        insertParam.add(jyzycgzidS);
                        String jfgzidS = map.get("jfgzid");
                        if (StringUtils.isEmpty(jfgzidS)) {
                            jfgzidS = "0";
                        }
                        insertParam.add(jfgzidS);
                        String jckfxsS = map.get("jckfxs");
                        if (StringUtils.isEmpty(jckfxsS)) {
                            jckfxsS = "0";
                        }
                        insertParam.add(jckfxsS);

                        String x1S = map.get("x1");
                        if (StringUtils.isEmpty(x1S)) {
                            x1S = "0";
                        }
                        insertParam.add(x1S);
                        String x2S = map.get("x2");
                        if (StringUtils.isEmpty(x2S)) {
                            x2S = "0";
                        }
                        insertParam.add(x2S);
                        String x3S = map.get("x3");
                        if (StringUtils.isEmpty(x3S)) {
                            x3S = "0";
                        }
                        insertParam.add(x3S);
                        String x4S = map.get("x4");
                        if (StringUtils.isEmpty(x4S)) {
                            x4S = "0";
                        }
                        insertParam.add(x4S);
                        String x5S = map.get("x5");
                        if (StringUtils.isEmpty(x5S)) {
                            x5S = "0";
                        }
                        insertParam.add(x5S);

                        String n1S = map.get("n1");
                        if (StringUtils.isEmpty(n1S)) {
                            n1S = "0";
                        }
                        insertParam.add(n1S);
                        String n2S = map.get("n2");
                        if (StringUtils.isEmpty(n2S)) {
                            n2S = "0";
                        }
                        insertParam.add(n2S);
                        String n3S = map.get("n3");
                        if (StringUtils.isEmpty(n3S)) {
                            n3S = "0";
                        }
                        insertParam.add(n3S);
                        String n4S = map.get("n4");
                        if (StringUtils.isEmpty(n4S)) {
                            n4S = "0";
                        }
                        insertParam.add(n4S);
                        String n5S = map.get("n5");
                        if (StringUtils.isEmpty(n5S)) {
                            n5S = "0";
                        }
                        insertParam.add(n5S);
                        String n6S = map.get("n6");
                        if (StringUtils.isEmpty(n6S)) {
                            n6S = "0";
                        }
                        insertParam.add(n6S);
                        insertParams.add(insertParam);
//                        rs.executeUpdate(insertDtSql, dataId, map.get("zbid"), map.get("zbmc"), map.get("zbms"), map.get("zbqz"),
//                                map.get("jyzycgzid"), map.get("jfgzid"), map.get("jckfxs"), map.get("x1"), map.get("x2"),map.get("x3")
//                        ,map.get("x4"),map.get("x5"),map.get("n1"),map.get("n2"),map.get("n3"),map.get("n4"),map.get("n5"),map.get("n6"));
                    }
                    if (!CollectionUtils.isEmpty(insertParams)) {
                        rs.executeBatchSql(insertDtSql, insertParams);
                    }
                }
            }

            // 权限重构
            ModeRightInfo modeRightInfo = new ModeRightInfo();
            modeRightInfo.setNewRight(true);
            modeRightInfo.editModeDataShare(1, Integer.parseInt(modeId), Integer.parseInt(cusId));
        } catch (Exception e) {
            baseBean.writeLog("generateIndexDt error:" + e);
            result.put("mes", "系统错误，请联系管理员！");
            result.put("code", "400");
            return result;
        }
        baseBean.writeLog("generateIndexDt end.");
        result.put("mes", "正在生成，请稍等！");
        result.put("code", "200");
        return result;
    }

    @Override
    public Map<String, Object> countIndexJyz(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        baseBean.writeLog("countIndexJyz start:" + params);
        try {
            // 考核计划
            String khjh = Util.null2String(params.get("khjh"));
            if (StringUtils.isEmpty(khjh)) {
                baseBean.writeLog("countIndexJyz khjh is null.");
                result.put("mes", "请选择考核计划！");
                result.put("code", "200");
                return result;
            }

            RecordSet rs = new RecordSet();
            // 获取考核计划所属年月
            String jhSzny = null;
            rs.execute("SELECT szny FROM uf_khjhdy WHERE id = " + khjh);
            if (rs.next()) {
                jhSzny = rs.getString("szny");
            }
            if (StringUtils.isEmpty(jhSzny)) {
                baseBean.writeLog("countIndexJyz jhSzny is null.");
                result.put("mes", "该考核计划所属年月获取失败，请检查！");
                result.put("code", "200");
                return result;
            }

            // 首先更新完成值结果表
//            updateWczjgData(jhSzny);

            // 考虑从导入表中取“指标权重”值
            Map<String, Map<String, String>> zbqzMap = new HashMap<>();
            rs.execute("SELECT * FROM uf_jyzdr");
            while (rs.next()) {
                String ygDr = rs.getString("yg");
                String szkhjhDr = rs.getString("szkhjh");
                String szkhfaDr = rs.getString("szkhfa");
                String dyzbDr = rs.getString("dyzb");
                String bdzDr = rs.getString("bdz");
                String mbzDr = rs.getString("mbz");
                String tzzDr = rs.getString("tzz");
                if (StringUtils.isEmpty(ygDr) || StringUtils.isEmpty(szkhjhDr) || StringUtils.isEmpty(szkhfaDr) || StringUtils.isEmpty(dyzbDr)) {
                    continue;
                }
                Map<String, String> bmtMap = new HashMap<>();
                bmtMap.put("bdz", bdzDr);
                bmtMap.put("mbz", mbzDr);
                bmtMap.put("tzz", tzzDr);
                zbqzMap.put(ygDr + "_" + szkhjhDr + "_" + szkhfaDr + "_" + dyzbDr, bmtMap);
            }

            RecordSet rs1 = new RecordSet();

            // 定义日期时间格式化器
//            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");

            rs.execute("select t1.*, t2.jsljid,t2.bdzbc,t2.tzzbc,t3.szny,t4.workcode,t4.companystartdate FROM (\n" +
                    " select a.*,b.szkhjh,b.szkhfa,b.yg from uf_ygmxzbdy_dt1 a, uf_ygmxzbdy b where a.mainid = b.id and b.szkhjh = " + khjh +
                    " ) t1 LEFT JOIN uf_jyzyclj t2 on t1.jyzycgzid = t2.id " +
                    " LEFT JOIN uf_khjhdy t3 on t1.szkhjh = t3.id " +
                    " LEFT JOIN hrmresource t4 ON t1.yg = t4.id ");
            while (rs.next()) {
                String id = rs.getString("id");
                String mainid = rs.getString("mainid");
                String zbid = rs.getString("zbid");
                String yg = rs.getString("yg");
                String szkhfa = rs.getString("szkhfa");
                String jyzycgzid = rs.getString("jyzycgzid");
                String jsljid = rs.getString("jsljid");
                String szny = rs.getString("szny");
                String workcode = rs.getString("workcode");
                String bdzbc = rs.getString("bdzbc");
                String companystartdate = rs.getString("companystartdate");
                if (StringUtils.isEmpty(bdzbc)) {
                    bdzbc = "0";
                }
                String tzzbc = rs.getString("tzzbc");
                if (StringUtils.isEmpty(tzzbc)) {
                    tzzbc = "0";
                }
                if (StringUtils.isEmpty(jsljid) || StringUtils.isEmpty(zbid) || StringUtils.isEmpty(jyzycgzid) || StringUtils.isEmpty(szny) || StringUtils.isEmpty(workcode)) {
                    continue;
                }

                String keyTemp = yg + "_" + khjh + "_" + szkhfa + "_" + zbid;
                if ((!CollectionUtils.isEmpty(zbqzMap)) && zbqzMap.containsKey(keyTemp)) {
                    Map<String, String> bmtMap = zbqzMap.get(keyTemp);
                    String bdz = bmtMap.get("bdz");
                    if (StringUtils.isEmpty(bdz) || new BigDecimal(bdz).compareTo(BigDecimal.ZERO) == 0) {
                        bdz = "0.00000000";
                    }
                    String mbz = bmtMap.get("mbz");
                    if (StringUtils.isEmpty(mbz) || new BigDecimal(mbz).compareTo(BigDecimal.ZERO) == 0) {
                        mbz = "0.00000000";
                    }
                    String tzz = bmtMap.get("tzz");
                    if (StringUtils.isEmpty(tzz) || new BigDecimal(tzz).compareTo(BigDecimal.ZERO) == 0) {
                        tzz = "0.00000000";
                    }
                    rs1.executeUpdate("UPDATE uf_ygmxzbdy_dt1 SET bdz = ?, mbz = ?, tzz = ? WHERE id = ?", bdz, mbz, tzz, id);
                } else {

                    if (StringUtils.equals(jsljid, "3")) {
                        String bdz = null;
                        String mbz = null;
                        String tzz = null;
                        String gdzTemp = null;
                        rs1.executeQuery("select gdjyz from uf_bzkhfa_dt1 where mainid = ?  and zbid = ?", szkhfa, zbid);
                        if (rs1.next()) {
                            gdzTemp = rs1.getString("gdjyz");
                        }
                        if (StringUtils.isEmpty(gdzTemp)) {
                            gdzTemp = "0";
                        }
                        mbz = gdzTemp;
                        bdz = new BigDecimal(mbz).add(new BigDecimal(bdzbc)).toString();
                        tzz = new BigDecimal(mbz).add(new BigDecimal(tzzbc)).toString();
                        if (new BigDecimal(mbz).compareTo(BigDecimal.ZERO) == 0) {
                            mbz = "0.00000000";
                        }
                        if (new BigDecimal(bdz).compareTo(BigDecimal.ZERO) == 0) {
                            bdz = "0.00000000";
                        }
                        if (new BigDecimal(tzz).compareTo(BigDecimal.ZERO) == 0) {
                            tzz = "0.00000000";
                        }
                        rs1.executeUpdate("UPDATE uf_ygmxzbdy_dt1 SET bdz = ?, mbz = ?, tzz = ? WHERE id = ?", bdz, mbz, tzz, id);
                    } else {
                        String tempSql = "select top 3 * from (\n" +
                                " select a.id,b.szny from uf_ygmxzbdy a, uf_khjhdy b where a.szkhjh = b.id and a.id != ? and a.yg = ? " +
                                ") a where CONVERT(varchar, a.szny, 120) < ? ORDER BY a.szny DESC";
                        String oneMonthAgoStr = null;
                        String twoMonthsAgoStr = null;
                        String threeMonthsAgoStr = null;
                        rs1.executeQuery(tempSql, mainid, yg, szny);
                        int i = 1;
                        while (rs1.next()) {
                            String sznyTemp = rs1.getString("szny");
                            if (i == 1) {
                                oneMonthAgoStr = sznyTemp;
                            }
                            if (i == 2) {
                                twoMonthsAgoStr = sznyTemp;
                            }
                            if (i == 3) {
                                threeMonthsAgoStr = sznyTemp;
                            }
                            i = i + 1;
                        }
                        if (StringUtils.isEmpty(oneMonthAgoStr)) {
                            continue;
                        }
                        if (StringUtils.isEmpty(twoMonthsAgoStr)) {
                            twoMonthsAgoStr = oneMonthAgoStr;
                        }
                        if (StringUtils.isEmpty(threeMonthsAgoStr)) {
                            threeMonthsAgoStr = oneMonthAgoStr;
                        }

                        String bdz = null;
                        String mbz = null;
                        String tzz = null;
                        if (StringUtils.equals(jsljid, "0")) {
                            String oneMonthAgoWcz = null;
                            String twoMonthsAgoWcz = null;
                            String threeMonthsAgoWcz = null;
                            rs1.executeQuery("select wcz, szny from uf_wczjgb where zbid = ? AND yggh = ? AND (szny = ? OR szny = ? " +
                                    "OR szny = ? )", zbid, workcode, threeMonthsAgoStr, twoMonthsAgoStr, oneMonthAgoStr);
                            while (rs1.next()) {
                                String sznyTemp = rs1.getString("szny");
                                String wczTemp = rs1.getString("wcz");
                                if (StringUtils.equals(sznyTemp, oneMonthAgoStr)) {
                                    oneMonthAgoWcz = wczTemp;
                                } else if (StringUtils.equals(sznyTemp, twoMonthsAgoStr)) {
                                    twoMonthsAgoWcz = wczTemp;
                                } else if (StringUtils.equals(sznyTemp, threeMonthsAgoStr)) {
                                    threeMonthsAgoWcz = wczTemp;
                                }
                            }
                            if (StringUtils.isEmpty(oneMonthAgoWcz)) {
                                oneMonthAgoWcz = "0";
                            }
                            if (StringUtils.isEmpty(twoMonthsAgoWcz)) {
                                twoMonthsAgoWcz = "0";
                            }
                            if (StringUtils.isEmpty(threeMonthsAgoWcz)) {
                                threeMonthsAgoWcz = "0";
                            }

                            String companystartdateNew = "";
                            if (StringUtils.isNotEmpty(companystartdate) && companystartdate.length() == 10) {
                                companystartdateNew = companystartdate.substring(0, 7);
                            }
                            if (StringUtils.isNotEmpty(companystartdateNew) && (StringUtils.equals(companystartdateNew, oneMonthAgoStr) ||
                                    StringUtils.equals(companystartdateNew, twoMonthsAgoStr) || StringUtils.equals(companystartdateNew, threeMonthsAgoStr))) {
                                mbz = (new BigDecimal(oneMonthAgoWcz).add(new BigDecimal(twoMonthsAgoWcz)).add(new BigDecimal(threeMonthsAgoWcz)))
                                        .divide(new BigDecimal("2"), 8, RoundingMode.HALF_UP).toString();
                                if (new BigDecimal(mbz).compareTo(BigDecimal.ZERO) == 0) {
                                    mbz = "0";
                                }
                                bdz = new BigDecimal(mbz).add(new BigDecimal(bdzbc)).toString();
                                tzz = new BigDecimal(mbz).add(new BigDecimal(tzzbc)).toString();
                            } else {
                                mbz = (new BigDecimal(oneMonthAgoWcz).add(new BigDecimal(twoMonthsAgoWcz)).add(new BigDecimal(threeMonthsAgoWcz)))
                                        .divide(new BigDecimal("3"), 8, RoundingMode.HALF_UP).toString();
                                if (new BigDecimal(mbz).compareTo(BigDecimal.ZERO) == 0) {
                                    mbz = "0";
                                }
                                bdz = new BigDecimal(mbz).add(new BigDecimal(bdzbc)).toString();
                                tzz = new BigDecimal(mbz).add(new BigDecimal(tzzbc)).toString();
                            }

                        }
                        if (StringUtils.equals(jsljid, "1")) {
                            String oneMonthAgoWcz = null;
                            String twoMonthsAgoWcz = null;
                            String threeMonthsAgoWcz = null;
                            rs1.executeQuery("select wcz, szny from uf_wczjgb where zbid = ? AND yggh = ? AND (szny = ? OR szny = ? " +
                                    "OR szny = ? )", zbid, workcode, threeMonthsAgoStr, twoMonthsAgoStr, oneMonthAgoStr);
                            while (rs1.next()) {
                                String sznyTemp = rs1.getString("szny");
                                String wczTemp = rs1.getString("wcz");
                                if (StringUtils.equals(sznyTemp, oneMonthAgoStr)) {
                                    oneMonthAgoWcz = wczTemp;
                                }
                                if (StringUtils.equals(sznyTemp, twoMonthsAgoStr)) {
                                    twoMonthsAgoWcz = wczTemp;
                                }
                                if (StringUtils.equals(sznyTemp, threeMonthsAgoStr)) {
                                    threeMonthsAgoWcz = wczTemp;
                                }
                            }
                            if (StringUtils.isEmpty(oneMonthAgoWcz)) {
                                oneMonthAgoWcz = "0";
                            }
                            if (StringUtils.isEmpty(twoMonthsAgoWcz)) {
                                twoMonthsAgoWcz = "0";
                            }
                            if (StringUtils.isEmpty(threeMonthsAgoWcz)) {
                                threeMonthsAgoWcz = "0";
                            }
                            BigDecimal multiply1 = new BigDecimal(oneMonthAgoWcz).multiply(new BigDecimal("0.6"));
                            BigDecimal multiply2 = new BigDecimal(twoMonthsAgoWcz).multiply(new BigDecimal("0.3"));
                            BigDecimal multiply3 = new BigDecimal(threeMonthsAgoWcz).multiply(new BigDecimal("0.1"));
                            mbz = multiply1.add(multiply2).add(multiply3).toString();
                            if (new BigDecimal(mbz).compareTo(BigDecimal.ZERO) == 0) {
                                mbz = "0";
                            }
                            bdz = new BigDecimal(mbz).add(new BigDecimal(bdzbc)).toString();
                            tzz = new BigDecimal(mbz).add(new BigDecimal(tzzbc)).toString();

                        }
                        if (StringUtils.equals(jsljid, "2")) {
                            String wczTemp = null;
                            rs1.executeQuery("select wcz, szny from uf_wczjgb where zbid = ? AND yggh = ? AND szny = ?", zbid,
                                    workcode, oneMonthAgoStr);
                            if (rs1.next()) {
                                wczTemp = rs1.getString("wcz");
                            }
                            if (StringUtils.isEmpty(wczTemp)) {
                                wczTemp = "0";
                            }
                            mbz = wczTemp;
                            bdz = new BigDecimal(mbz).add(new BigDecimal(bdzbc)).toString();
                            tzz = new BigDecimal(mbz).add(new BigDecimal(tzzbc)).toString();
                        }
                        if (StringUtils.equals(jsljid, "3")) {
                            String gdzTemp = null;
                            rs1.executeQuery("select gdjyz from uf_bzkhfa_dt1 where mainid = ?  and zbid = ?", szkhfa, zbid);
                            if (rs1.next()) {
                                gdzTemp = rs1.getString("gdjyz");
                            }
                            if (StringUtils.isEmpty(gdzTemp)) {
                                gdzTemp = "0";
                            }
                            mbz = gdzTemp;
                            bdz = new BigDecimal(mbz).add(new BigDecimal(bdzbc)).toString();
                            tzz = new BigDecimal(mbz).add(new BigDecimal(tzzbc)).toString();
                        }

                        if (new BigDecimal(mbz).compareTo(BigDecimal.ZERO) == 0) {
                            mbz = "0.00000000";
                        }
                        if (new BigDecimal(bdz).compareTo(BigDecimal.ZERO) == 0) {
                            bdz = "0.00000000";
                        }
                        if (new BigDecimal(tzz).compareTo(BigDecimal.ZERO) == 0) {
                            tzz = "0.00000000";
                        }

                        rs1.executeUpdate("UPDATE uf_ygmxzbdy_dt1 SET bdz = ?, mbz = ?, tzz = ? WHERE id = ?", bdz, mbz, tzz, id);
                    }
                }
            }
        } catch (Exception e) {
            baseBean.writeLog("countIndexJyz error:" + e);
            result.put("mes", "系统错误，请联系管理员！");
            result.put("code", "400");
            return result;
        }
        baseBean.writeLog("countIndexJyz end.");
        result.put("mes", "正在计算，请稍等！");
        result.put("code", "200");
        return result;
    }

    @Override
    public Map<String, Object> countIndexScoring(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        baseBean.writeLog("countIndexScoring start:" + params);
        try {
            // 考核计划
            String khjh = Util.null2String(params.get("khjh"));
            if (StringUtils.isEmpty(khjh)) {
                baseBean.writeLog("countIndexScoring khjh is null.");
                result.put("mes", "请选择考核计划！");
                result.put("code", "200");
                return result;
            }

            RecordSet rs = new RecordSet();
            // 获取考核计划所属年月
            String jhSzny = null;
            rs.execute("SELECT szny FROM uf_khjhdy WHERE id = " + khjh);
            if (rs.next()) {
                jhSzny = rs.getString("szny");
            }
            if (StringUtils.isEmpty(jhSzny)) {
                baseBean.writeLog("countIndexScoring jhSzny is null.");
                result.put("mes", "该考核计划所属年月获取失败，请检查！");
                result.put("code", "200");
                return result;
            }

            // 首先更新完成值结果表
//            updateWczjgData(jhSzny);

            // 人员
            String ry = Util.null2String(params.get("ry"));
            Set<String> rySet = new HashSet<>();

            // 先删除该考核计划关联的数据
            Set<String> needDelIdSet = new HashSet<>();
            String queryIdSql = "SELECT id FROM uf_jxdfjgb WHERE khjh = " + khjh;
            if (StringUtils.isNotEmpty(ry)) {
                queryIdSql = queryIdSql + " AND yg in (" + ry + ")";
                rySet.addAll(Arrays.asList(ry.split(",")));
            }
            rs.execute(queryIdSql);
            while (rs.next()) {
                String id = rs.getString("id");
                if (StringUtils.isNotEmpty(id)) {
                    needDelIdSet.add(id);
                }
            }
            if (!CollectionUtils.isEmpty(needDelIdSet)) {
                rs.execute("DELETE FROM uf_jxdfjgb_dt1 WHERE mainid in (" + String.join(",", needDelIdSet) + ")");
                rs.execute("DELETE FROM uf_jxdfjgb WHERE id in (" + String.join(",", needDelIdSet) + ")");
            }

            // 定义一个DateTimeFormatter对象，用于解析年月字符串
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
//            DateTimeFormatter formatterRq = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            // 将字符串解析为YearMonth对象
            YearMonth yearMonth = YearMonth.parse(jhSzny, formatter);
            // 从YearMonth对象中提取年份与月份
            int year = yearMonth.getYear();
            int month = yearMonth.getMonthValue();
//            int lastDay = yearMonth.lengthOfMonth();

            // 获取保护期人员
            Set<String> protectSet = new HashSet<>();
            rs.executeQuery("SELECT ygxm FROM uf_khbhqxxrg WHERE lx = 1 AND ((YEAR(CONVERT(date, ksrq)) = ? AND MONTH(CONVERT(date, ksrq)) = ?)" +
                    " OR (YEAR(CONVERT(date, jsrq)) = ? AND MONTH(CONVERT(date, jsrq)) = ?))", year, month, year, month);
            while (rs.next()) {
                String ygxm = rs.getString("ygxm");
                if (StringUtils.isNotEmpty(ygxm)) {
                    protectSet.add(ygxm);
                }
            }

            // 绩效得分结果建模id
            String modeId = rs.getPropValue("qz_jx_zm_prop", "jx_score_res_mode_id");
            // 绩效得分结果查询id
            String cusId = rs.getPropValue("qz_jx_zm_prop", "jx_score_res_cus_id");
            String gwFieldId = rs.getPropValue("qz_jx_zm_prop", "gw_field_id");

            // 计分规则-越来越高id
            String ruleHigherId = rs.getPropValue("qz_jx_zm_prop", "jf_rule_higher_id");
            // 计分规则-越来越低id
            String ruleLowerId = rs.getPropValue("qz_jx_zm_prop", "jf_rule_lower_id");
            // 计分规则-计次不占权重id
            String rule3 = rs.getPropValue("qz_jx_zm_prop", "jf_rule_count_without_weighting_id");
            // 计分规则-以完成值作为得分id
            String rule4 = rs.getPropValue("qz_jx_zm_prop", "jf_rule_base_complete_id");
            // 计分规则-完成值区间固定得分id
            String rule5 = rs.getPropValue("qz_jx_zm_prop", "jf_rule_complete_interval_id");

            // 获取岗位名称为“销售经理”的人员id
            String aboveOneGw = rs.getPropValue("qz_jx_zm_prop", "bjjxxs_above_one");
            Set<String> aboveOneGwSet = new HashSet<>();
            if (StringUtils.isNotEmpty(aboveOneGw)) {
                String zdgwSql = "SELECT b.id,b." + gwFieldId + ",c.gwmc FROM cus_fielddata b LEFT JOIN uf_JCL_GWGL c " +
                        " ON b." + gwFieldId + " = c.id WHERE b.scope = 'HrmCustomFieldByInfoType' AND b.scopeid = 3 AND b." + gwFieldId
                        + " is not null AND (";
                String[] aboveOneGwArr = aboveOneGw.split(",");
                for (String gwmc : aboveOneGwArr) {
                    zdgwSql = zdgwSql + " c.gwmc = '" + gwmc + "' OR";
                }
                zdgwSql = zdgwSql.substring(0, zdgwSql.length() - 2);
                zdgwSql = zdgwSql + ")";
                rs.execute(zdgwSql);
                while (rs.next()) {
                    String id = rs.getString("id");
                    String gwmc = rs.getString("gwmc");
                    if (StringUtils.isEmpty(id) || StringUtils.isEmpty(gwmc)) {
                        continue;
                    }
                    aboveOneGwSet.add(id);
                }
            }

            RecordSet rs1 = new RecordSet();
            Map<String, String> dfMap = new HashMap<>();
            Map<String, String> wclMap = new HashMap<>();
            Map<String, String> szfbMap = new HashMap<>();
            Map<String, String> szbmMap = new HashMap<>();
            Map<String, String> szgwMap = new HashMap<>();
            Map<String, String> ygghMap = new HashMap<>();
            Map<String, String> bzjxxsMap = new HashMap<>();
            Map<String, String> sfscMap = new HashMap<>();
            Map<String, List<Map<String, String>>> dfMainMap = new HashMap<>();

            rs.execute("SELECT t1.*, t2.szny, t4.workcode, t4.subcompanyid1, t4.departmentid, t3.wcz, t5.qzfbpxyxj," +
                    "    t6.jxxssx, t6.jxxsxx, e." + gwFieldId +
                    " FROM (SELECT a.*, b.szkhjh, b.szkhfa, b.sfscbzjxxs, b.yg from uf_ygmxzbdy_dt1 a, uf_ygmxzbdy b WHERE a.mainid = b.id" +
                    " AND b.szkhjh = " + khjh + ") t1 LEFT JOIN uf_khjhdy t2 on t1.szkhjh = t2.id " +
                    " LEFT JOIN hrmresource t4 on t1.yg = t4.id " +
                    " LEFT JOIN uf_zbk t5 on t1.zbid = t5.id " +
                    " LEFT JOIN uf_bzkhfa t6 on t1.szkhfa = t6.id " +
                    " LEFT JOIN cus_fielddata e ON e.id = t1.yg AND e.scope = 'HrmCustomFieldByInfoType' AND e.scopeid = 3 " +
                    " LEFT JOIN uf_wczjgb t3 on t1.zbid = t3.zbid and t2.szny = t3.szny and t4.workcode = t3.yggh");

            while (rs.next()) {
                String id = rs.getString("id");
                String yg = rs.getString("yg");
                String szkhjh = rs.getString("szkhjh");
                String szkhfa = rs.getString("szkhfa");
                String zbid = rs.getString("zbid");
                String qzfbpxyxj = rs.getString("qzfbpxyxj");
                String jxxssx = rs.getString("jxxssx");
                String jxxsxx = rs.getString("jxxsxx");
                String x1 = rs.getString("x1");
                String x2 = rs.getString("x2");
                String x3 = rs.getString("x3");
                String x4 = rs.getString("x4");
                String x5 = rs.getString("x5");
                String n1 = rs.getString("n1");
                String n2 = rs.getString("n2");
                String n3 = rs.getString("n3");
                String n4 = rs.getString("n4");
                String n5 = rs.getString("n5");
                String n6 = rs.getString("n6");
                String wcz = rs.getString("wcz");
                String bdz = rs.getString("bdz");
                String mbz = rs.getString("mbz");
                String tzz = rs.getString("tzz");
                String jfgzid = rs.getString("jfgzid");
                String zbqz = rs.getString("zbqz");
                String jckfxs = rs.getString("jckfxs");
                String subcompanyid1 = rs.getString("subcompanyid1");
                String departmentid = rs.getString("departmentid");
                String szgwTemp = rs.getString(gwFieldId);
                String workcode = rs.getString("workcode");
                String sfscbzjxxs = rs.getString("sfscbzjxxs");
                if (StringUtils.isEmpty(jfgzid) || StringUtils.isEmpty(yg) || StringUtils.isEmpty(szkhfa) || StringUtils.isEmpty(szkhjh)
                        || StringUtils.isEmpty(subcompanyid1) || StringUtils.isEmpty(departmentid) || StringUtils.isEmpty(szgwTemp)
                        || StringUtils.isEmpty(workcode)) {
                    continue;
                }
                if ((!CollectionUtils.isEmpty(rySet)) && !rySet.contains(yg)) {
                    continue;
                }

                szfbMap.put(yg, subcompanyid1);
                szbmMap.put(yg, departmentid);
                szgwMap.put(yg, szgwTemp);
                ygghMap.put(yg, workcode);
                boolean isGoingA = true;
                boolean isGoingB = true;
                if (StringUtils.equals(jfgzid, ruleHigherId) || StringUtils.equals(jfgzid, ruleLowerId)) {
                    if (StringUtils.isEmpty(bdz) || StringUtils.isEmpty(mbz) || StringUtils.isEmpty(tzz)) {
                        isGoingA = false;
                    }
                }
                if (StringUtils.equals(jfgzid, rule5) && (StringUtils.isEmpty(x1) || StringUtils.isEmpty(x2) || StringUtils.isEmpty(x3) || StringUtils.isEmpty(x4)
                        || StringUtils.isEmpty(x5) || StringUtils.isEmpty(n1) || StringUtils.isEmpty(n2) || StringUtils.isEmpty(n3) ||
                        StringUtils.isEmpty(n4) || StringUtils.isEmpty(n5) || StringUtils.isEmpty(n6))) {
                    isGoingB = false;
                }
                if (StringUtils.isEmpty(zbqz)) {
                    zbqz = "0";
                }
                if (StringUtils.isEmpty(jckfxs)) {
                    jckfxs = "0";
                }
                String df = null;
                String wcl = null;
                if (StringUtils.isNotEmpty(wcz) && isGoingA && isGoingB) {
                    BigDecimal wczBd = new BigDecimal(wcz);

                    if (StringUtils.equals(jfgzid, ruleHigherId)) {
                        BigDecimal bdzBd = new BigDecimal(bdz);
                        BigDecimal mbzBd = new BigDecimal(mbz);
                        BigDecimal tzzBd = new BigDecimal(tzz);
                        if (wczBd.compareTo(bdzBd) < 0) {
                            df = "0";
                        } else if (wczBd.compareTo(bdzBd) >= 0 && wczBd.compareTo(mbzBd) < 0) {
                            BigDecimal dfBd = ((wczBd.subtract(bdzBd)).divide((mbzBd.subtract(bdzBd)), 8, RoundingMode.HALF_UP))
                                    .multiply(new BigDecimal(zbqz)).multiply(new BigDecimal("100"));
                            if (dfBd.compareTo(BigDecimal.ZERO) == 0) {
                                df = "0";
                            } else {
                                df = dfBd.toString();
                            }
                        } else if (wczBd.compareTo(mbzBd) >= 0 && wczBd.compareTo(tzzBd) < 0) {
                            BigDecimal dfBd = (((wczBd.subtract(mbzBd)).divide((tzzBd.subtract(mbzBd)), 8, RoundingMode.HALF_UP))
                                    .add(new BigDecimal("1"))).multiply(new BigDecimal(zbqz)).multiply(new BigDecimal("100"));
                            if (dfBd.compareTo(BigDecimal.ZERO) == 0) {
                                df = "0";
                            } else {
                                df = dfBd.toString();
                            }
                        } else if (wczBd.compareTo(tzzBd) >= 0) {
                            df = new BigDecimal("200").multiply(new BigDecimal(zbqz)).toString();
                        }

                        if (mbzBd.compareTo(BigDecimal.ZERO) != 0) {
                            wcl = wczBd.multiply(new BigDecimal("100")).multiply(new BigDecimal(zbqz)).divide(mbzBd, 8, RoundingMode.HALF_UP).toPlainString();
                        }
                    } else if (StringUtils.equals(jfgzid, ruleLowerId)) {
                        BigDecimal bdzBd = new BigDecimal(bdz);
                        BigDecimal mbzBd = new BigDecimal(mbz);
                        BigDecimal tzzBd = new BigDecimal(tzz);
                        if (wczBd.compareTo(bdzBd) > 0) {
                            df = "0";
                        } else if (wczBd.compareTo(bdzBd) <= 0 && wczBd.compareTo(mbzBd) > 0) {
                            BigDecimal dfBd = ((wczBd.subtract(bdzBd)).divide((mbzBd.subtract(bdzBd)), 8, RoundingMode.HALF_UP))
                                    .multiply(new BigDecimal(zbqz)).multiply(new BigDecimal("100"));
                            if (dfBd.compareTo(BigDecimal.ZERO) == 0) {
                                df = "0";
                            } else {
                                df = dfBd.toString();
                            }
                        } else if (wczBd.compareTo(mbzBd) <= 0 && wczBd.compareTo(tzzBd) > 0) {
                            BigDecimal dfBd = (((wczBd.subtract(mbzBd)).divide((tzzBd.subtract(mbzBd)), 8, RoundingMode.HALF_UP))
                                    .add(new BigDecimal("1"))).multiply(new BigDecimal(zbqz)).multiply(new BigDecimal("100"));
                            if (dfBd.compareTo(BigDecimal.ZERO) == 0) {
                                df = "0";
                            } else {
                                df = dfBd.toString();
                            }
                        } else if (wczBd.compareTo(tzzBd) <= 0) {
                            df = new BigDecimal("200").multiply(new BigDecimal(zbqz)).toString();
                        }

                        if (mbzBd.compareTo(BigDecimal.ZERO) != 0) {
                            wcl = wczBd.multiply(new BigDecimal("-100")).multiply(new BigDecimal(zbqz)).divide(mbzBd, 8, RoundingMode.HALF_UP).toPlainString();
                        }
                    } else if (StringUtils.equals(jfgzid, rule3)) {
                        BigDecimal dfBd = wczBd.multiply(new BigDecimal(jckfxs));
                        if (dfBd.compareTo(BigDecimal.ZERO) == 0) {
                            df = "0";
                        } else {
                            df = dfBd.toString();
                        }

                        wcl = df;
                    } else if (StringUtils.equals(jfgzid, rule4)) {
                        df = wcz;
                        wcl = wczBd.multiply(new BigDecimal("100")).multiply(new BigDecimal(zbqz)).toPlainString();
                    } else if (StringUtils.equals(jfgzid, rule5)) {
                        BigDecimal x1Bd = new BigDecimal(x1);
                        BigDecimal x2Bd = new BigDecimal(x2);
                        BigDecimal x3Bd = new BigDecimal(x3);
                        BigDecimal x4Bd = new BigDecimal(x4);
                        BigDecimal x5Bd = new BigDecimal(x5);
                        if (wczBd.compareTo(x1Bd) < 0) {
                            df = n1;
                        } else if (wczBd.compareTo(x1Bd) >= 0 && wczBd.compareTo(x2Bd) < 0) {
                            df = n2;
                        } else if (wczBd.compareTo(x2Bd) >= 0 && wczBd.compareTo(x3Bd) < 0) {
                            df = n3;
                        } else if (wczBd.compareTo(x3Bd) >= 0 && wczBd.compareTo(x4Bd) < 0) {
                            df = n4;
                        } else if (wczBd.compareTo(x4Bd) >= 0 && wczBd.compareTo(x5Bd) < 0) {
                            df = n5;
                        } else if (wczBd.compareTo(x5Bd) >= 0) {
                            df = n6;
                        }
                        if (StringUtils.isNotEmpty(df)) {
                            wcl = new BigDecimal(df).multiply(new BigDecimal("100")).multiply(new BigDecimal(zbqz)).toPlainString();
                        }
                    }
                }
                if (StringUtils.isEmpty(df) || new BigDecimal(df).compareTo(BigDecimal.ZERO) == 0) {
                    df = "0";
                }
                baseBean.writeLog("countIndexScoring df、wcl:" + df + "、" + wcl + "、" + id);
                rs1.executeUpdate("UPDATE uf_ygmxzbdy_dt1 SET df = ? WHERE id = ?", df, id);

//                BigDecimal bzjxxs = new BigDecimal(df).divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);
                if (StringUtils.isEmpty(jxxssx)) {
                    jxxssx = "0";
                }
                if (StringUtils.isEmpty(jxxsxx)) {
                    jxxsxx = "0";
                }
//                if (bzjxxs.compareTo(new BigDecimal(jxxssx)) > 0) {
//                    bzjxxs = new BigDecimal(jxxssx);
//                }
//                if (bzjxxs.compareTo(new BigDecimal(jxxsxx)) < 0) {
//                    bzjxxs = new BigDecimal(jxxsxx);
//                }
//                if (bzjxxs.compareTo(new BigDecimal(jxxsxx)) == 0) {
//                    bzjxxs = new BigDecimal("0");
//                }
                String key = yg + "-" + szkhjh + "-" + szkhfa;
                if ((!CollectionUtils.isEmpty(dfMap)) && dfMap.containsKey(key)) {
                    String dfInt = dfMap.get(key);
                    if (StringUtils.isEmpty(dfInt)) {
                        dfInt = "0";
                    }
                    dfMap.put(key, new BigDecimal(df).add(new BigDecimal(dfInt)).toString());
                } else {
                    dfMap.put(key, df);
                }

                if (StringUtils.isEmpty(wcl) || new BigDecimal(wcl).compareTo(BigDecimal.ZERO) == 0) {
                    wcl = "0";
                }
                if ((!CollectionUtils.isEmpty(wclMap)) && wclMap.containsKey(key)) {
                    String wclTemp = wclMap.get(key);
                    if (StringUtils.isEmpty(wclTemp)) {
                        wclTemp = "0";
                    }
                    wclMap.put(key, new BigDecimal(wcl).add(new BigDecimal(wclTemp)).toString());
                } else {
                    wclMap.put(key, wcl);
                }

                sfscMap.put(key, sfscbzjxxs);
                bzjxxsMap.put(key, jxxssx + "_" + jxxsxx);

                Map<String, String> mainMap = new HashMap<>();
                mainMap.put("zbid", zbid);
                mainMap.put("zbqz", zbqz);
                mainMap.put("zbdf", df);
                mainMap.put("zbyxj", qzfbpxyxj);
                mainMap.put("wcz", wcz);
                mainMap.put("mbz", mbz);
                mainMap.put("wcl", wcl);
                if ((!CollectionUtils.isEmpty(dfMainMap)) && dfMainMap.containsKey(key)) {
                    List<Map<String, String>> mapList = dfMainMap.get(key);
                    mapList.add(mainMap);
                    dfMainMap.put(key, mapList);
                } else {
                    List<Map<String, String>> mapList = new ArrayList<>();
                    mapList.add(mainMap);
                    dfMainMap.put(key, mapList);
                }
            }

            if (CollectionUtils.isEmpty(dfMap)) {
                baseBean.writeLog("dfMap is null.");
            } else {
                baseBean.writeLog("dfMap size is:" + dfMap.size());
            }
            if (!CollectionUtils.isEmpty(dfMap)) {
                SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
                SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
                String insertSql = "INSERT INTO uf_jxdfjgb (khjh, khfa, yg, df, bzjxxs, szfb, szbm, szgw, yggh, sfwbhq,sfscbzjxxs,wcl,formmodeid, MODEUUID, modedatacreater," +
                        "modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                List<List> insertParams = new ArrayList<>();
                for (Map.Entry<String, String> entry : dfMap.entrySet()) {
                    String key = entry.getKey();
                    String value = entry.getValue();
                    String yg = key.split("-")[0];
                    String szkhjh = key.split("-")[1];
                    String szkhfa = key.split("-")[2];
                    String jxxs = bzjxxsMap.get(key);
                    String jxxssx = "0";
                    String jxxsxx = "0";
                    if (StringUtils.isNotEmpty(jxxs)) {
                        String[] jsxsArr = jxxs.split("_");
                        if (jsxsArr.length == 2) {
                            jxxssx = jsxsArr[0];
                            jxxsxx = jsxsArr[1];
                        }
                    }
                    BigDecimal bzjxxs = new BigDecimal(value).divide(new BigDecimal("100"), 4, RoundingMode.HALF_UP);
                    if (StringUtils.isEmpty(jxxssx)) {
                        jxxssx = "0";
                    }
                    if (StringUtils.isEmpty(jxxsxx)) {
                        jxxsxx = "0";
                    }
                    if (bzjxxs.compareTo(new BigDecimal(jxxssx)) > 0) {
                        bzjxxs = new BigDecimal(jxxssx);
                    }
                    if (bzjxxs.compareTo(new BigDecimal(jxxsxx)) <= 0) {
                        bzjxxs = new BigDecimal(jxxsxx);
                    }
                    String sfwbhq = "1";
                    if ((!CollectionUtils.isEmpty(protectSet)) && protectSet.contains(yg)) {
                        bzjxxs = new BigDecimal("1");
                        sfwbhq = "0";
                    }
                    if ((!CollectionUtils.isEmpty(aboveOneGwSet)) && aboveOneGwSet.contains(yg) && bzjxxs.compareTo(new BigDecimal("1")) < 0) {
                        bzjxxs = new BigDecimal("1");
                    }
                    String sfsc = sfscMap.get(key);
                    if (StringUtils.isEmpty(sfsc)) {
                        sfsc = "0";
                    }
                    if (new BigDecimal(sfsc).compareTo(new BigDecimal("1")) == 0) {
                        bzjxxs = new BigDecimal("0");
                    }
//                    if (bzjxxs.compareTo(new BigDecimal(jxxsxx)) == 0) {
//                        bzjxxs = new BigDecimal("0");
//                    }
                    String uuidTemp = UUID.randomUUID() + yg;

                    String szfbT = szfbMap.get(yg);
                    String szbmT = szbmMap.get(yg);
                    String szgwT = szgwMap.get(yg);
                    String ygghT = ygghMap.get(yg);
                    String wcl = wclMap.get(key);
                    if (StringUtils.isEmpty(wcl)) {
                        wcl = "0";
                    }
                    rs.executeUpdate(insertSql, szkhjh, szkhfa, yg, value, bzjxxs, szfbT, szbmT, szgwT, ygghT, sfwbhq, sfsc, wcl, modeId, uuidTemp, "1", "0", sdfDate.format(new Date()),
                            sdfTime.format(new Date()));
                    List<Map<String, String>> mapList = dfMainMap.get(key);
                    if (!CollectionUtils.isEmpty(mapList)) {
                        String dataId = null;
                        rs.executeQuery("SELECT id FROM uf_jxdfjgb WHERE MODEUUID = ?", uuidTemp);
                        if (rs.next()) {
                            dataId = rs.getString("id");
                        }
                        for (Map<String, String> map : mapList) {
                            String zbid = map.get("zbid");
                            if (StringUtils.isEmpty(zbid)) {
                                continue;
                            }
                            String zbqz = map.get("zbqz");
                            if (StringUtils.isEmpty(zbqz)) {
                                zbqz = "0";
                            }
                            String zbdf = map.get("zbdf");
                            if (StringUtils.isEmpty(zbdf)) {
                                zbdf = "0";
                            }
                            String zbyxj = map.get("zbyxj");
                            if (StringUtils.isEmpty(zbyxj)) {
                                zbyxj = "0";
                            }

                            String wcz = map.get("wcz");
                            if (StringUtils.isEmpty(wcz)) {
                                wcz = "0";
                            }
                            String mbz = map.get("mbz");
                            if (StringUtils.isEmpty(mbz)) {
                                mbz = "0";
                            }
                            String wclDt = map.get("wcl");
                            if (StringUtils.isEmpty(wclDt)) {
                                wclDt = "0";
                            }
                            List insertParam = new ArrayList<>();
                            insertParam.add(dataId);
                            insertParam.add(zbid);
                            insertParam.add(zbqz);
                            insertParam.add(yg);
                            insertParam.add(zbdf);
                            insertParam.add(zbyxj);
                            insertParam.add(mbz);
                            insertParam.add(wcz);
                            insertParam.add(wclDt);
                            insertParams.add(insertParam);
                        }
                    }
                }
                if (!CollectionUtils.isEmpty(insertParams)) {
                    String insertSqlA = "INSERT INTO uf_jxdfjgb_dt1 (mainid,zb, zbqz, yg, df, yxj,bzz,wcz,wcl) VALUES (?,?,?,?,?,?,?,?,?)";
                    rs.executeBatchSql(insertSqlA, insertParams);
                }
            }

            // 进行"绩效偏离度"指标的计算
            // 完成值结果建模id
            RecordSet wczRs = new RecordSet();
            String modeIdNew = wczRs.getPropValue("qz_jx_zm_prop", "wczjgb_mode_id");
            // 完成值结果查询id
            String cusIdNew = wczRs.getPropValue("qz_jx_zm_prop", "wczjgb_cus_id");
            SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
            SimpleDateFormat dtFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            List<List> updateList = new ArrayList<>();
            List<List> insertList = new ArrayList<>();

            Set<String> zbSet = new HashSet<>();
            String querySqlNew = " SELECT a1.*, e." + gwFieldId + " FROM (SELECT b.yg,b.szkhjh,c.szny, d.workcode,d.subcompanyid1,d.departmentid " +
                    " FROM uf_ygmxzbdy_dt1 a, uf_ygmxzbdy b, uf_khjhdy c, hrmresource d " +
                    " WHERE a.mainid = b.id and b.szkhjh = c.id AND b.yg = d.id AND a.zbid = ? AND c.szny = ?) a1 " +
                    " LEFT JOIN cus_fielddata e ON e.id = a1.yg AND e.scope = 'HrmCustomFieldByInfoType' AND e.scopeid = 3";
            wczRs.execute("SELECT * FROM uf_rlzbjspzglb WHERE jszb = 2 AND (zt is null or zt != 0)");
            while (wczRs.next()) {
                String zb = wczRs.getString("zb");
                String fwsql = wczRs.getString("fwsql");
                String jszb = wczRs.getString("jszb");
                if (StringUtils.isEmpty(zb) || StringUtils.isEmpty(fwsql) || StringUtils.isEmpty(jszb) || StringUtils.equals(jszb, "2")) {
                    continue;
                }
                Set<String> rySetNew = new HashSet<>();
                Map<String, String> ghMap = new HashMap<>();
                Map<String, String> fbMap = new HashMap<>();
                Map<String, String> bmMap = new HashMap<>();
                Map<String, String> gwMap = new HashMap<>();
                rs1.executeQuery(querySqlNew, zb, jhSzny);
                while (rs1.next()) {
                    String ygTemp = rs1.getString("yg");
                    String workcode = rs1.getString("workcode");
                    String subcompanyid1 = rs1.getString("subcompanyid1");
                    String departmentid = rs1.getString("departmentid");
                    String szgw = rs1.getString(gwFieldId);
                    if (StringUtils.isEmpty(ygTemp) || StringUtils.isEmpty(workcode) || StringUtils.isEmpty(subcompanyid1)
                            || StringUtils.isEmpty(departmentid) || StringUtils.isEmpty(szgw)) {
                        continue;
                    }
                    rySetNew.add(ygTemp);
                    ghMap.put(ygTemp, workcode);
                    fbMap.put(ygTemp, subcompanyid1);
                    bmMap.put(ygTemp, departmentid);
                    gwMap.put(ygTemp, szgw);
                }

                if (CollectionUtils.isEmpty(rySetNew)) {
                    continue;
                }

                String resValueT = "0";

                List<String> dataIdSet = new ArrayList<>();
                rs1.execute(fwsql);
                while (rs1.next()) {
                    String dataId = rs1.getString(1);
                    if (StringUtils.isEmpty(dataId)) {
                        continue;
                    }
                    if (rySetNew.contains(dataId)) {
                        continue;
                    }
                    dataIdSet.add(dataId);
                }

                if (CollectionUtils.isEmpty(dataIdSet)) {
                    continue;
                }

                zbSet.add(zb);

                int batchSize = 1000; // 每个小集合的大小
                int size = dataIdSet.size(); // 原始集合的大小
                int numberOfBatches = (int) Math.ceil((double) size / batchSize); // 划分的小集合数量
                List<List<String>> dividedLists = new ArrayList<>(); // 存储划分后的小集合

                for (int i = 0; i < numberOfBatches; i++) {
                    int fromIndex = i * batchSize;
                    int toIndex = Math.min((i + 1) * batchSize, size);
                    List<String> batch = dataIdSet.subList(fromIndex, toIndex);
                    dividedLists.add(batch);
                }

                Map<String, String> mapJgb = new HashMap<>();
                rs1.executeQuery("SELECT * FROM uf_wczjgb where szny = ? AND zbid = ?", jhSzny, zb);
                while (rs1.next()) {
                    String id = rs1.getString("id");
                    String yggh = rs1.getString("yggh");
                    mapJgb.put(yggh, id);
                }

                BigDecimal dfbD = new BigDecimal("0");
                for (List<String> batch : dividedLists) {
                    String ids = String.join(",", batch);
                    rs1.execute("SELECT sum(df) as sumdf FROM uf_jxdfjgb WHERE khjh = " + khjh + " AND yg in (" + ids + ")");
                    while (rs1.next()) {
                        String sumdf = rs1.getString("sumdf");
                        if (StringUtils.isEmpty(sumdf)) {
                            sumdf = "0";
                        }
                        dfbD = dfbD.add(new BigDecimal(sumdf));
                    }
                }
                if (dfbD.compareTo(BigDecimal.ZERO) > 0) {
                    BigDecimal resValueBd = dfbD.divide(new BigDecimal(String.valueOf(size)), 8, RoundingMode.DOWN);
                    resValueBd = resValueBd.subtract(new BigDecimal("100"));
                    if (resValueBd.compareTo(BigDecimal.ZERO) < 0) {
                        resValueBd = BigDecimal.ZERO.subtract(resValueBd);
                    }
                    if (resValueBd.compareTo(BigDecimal.ZERO) == 0) {
                        resValueT = "0";
                    } else if (resValueBd.compareTo(new BigDecimal("100")) >= 0) {
                        resValueT = "100";
                    } else {
                        resValueT = resValueBd.toString();
                    }
                }

                for (String lsry : rySetNew) {
                    String gh = ghMap.get(lsry);
                    if (StringUtils.isEmpty(gh)) {
                        continue;
                    }
                    String szfb = fbMap.get(lsry);
                    String szbm = bmMap.get(lsry);
                    String szgw = gwMap.get(lsry);
                    if ((!CollectionUtils.isEmpty(mapJgb)) && mapJgb.containsKey(gh)) {
                        String id = mapJgb.get(gh);
                        List arrayList = new ArrayList<>();
                        arrayList.add(resValueT);
                        arrayList.add(dtFormat.format(new Date()));
                        arrayList.add(szfb);
                        arrayList.add(szbm);
                        arrayList.add(szgw);
                        arrayList.add(id);
                        updateList.add(arrayList);
                    } else {
                        List arrayList = new ArrayList<>();
                        arrayList.add(gh);
                        arrayList.add(zb);
                        arrayList.add(resValueT);
                        arrayList.add(jhSzny);
                        arrayList.add(lsry);
                        arrayList.add(szfb);
                        arrayList.add(szbm);
                        arrayList.add(szgw);
                        arrayList.add(modeIdNew);
                        arrayList.add(cusIdNew);
                        arrayList.add("1");
                        arrayList.add("0");
                        arrayList.add(sdfDate.format(new Date()));
                        arrayList.add(sdfTime.format(new Date()));
                        insertList.add(arrayList);
                    }
                }
            }

            if (CollectionUtils.isEmpty(updateList)) {
                baseBean.writeLog("countIndexScoring updateList is null.");
            } else {
                baseBean.writeLog("countIndexScoring updateList size is:" + updateList.size());
                String updateSql = "UPDATE uf_wczjgb SET wcz = ?,modedatamodifydatetime = ?, szfb = ?, szbm = ?," +
                        " szgw = ? WHERE id = ?";
                wczRs.executeBatchSql(updateSql, updateList);
            }

            if (CollectionUtils.isEmpty(insertList)) {
                baseBean.writeLog("countIndexScoring insertList is null.");
            } else {
                baseBean.writeLog("countIndexScoring insertList size is:" + insertList.size());
                String insertSql = "INSERT INTO uf_wczjgb (yggh,zbid,wcz,szny,ry,szfb,szbm,szgw,formmodeid, MODEUUID, modedatacreater," +
                        "modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                wczRs.executeBatchSql(insertSql, insertList);
            }

            // 权限重构
            ModeRightInfo modeRightInfo = new ModeRightInfo();
            modeRightInfo.setNewRight(true);
            modeRightInfo.editModeDataShare(1, Integer.parseInt(modeIdNew), Integer.parseInt(cusIdNew));

            if (!CollectionUtils.isEmpty(zbSet)) {
                handleJxAgain(khjh, zbSet, protectSet, aboveOneGwSet);
            }

            modeRightInfo.setNewRight(true);
            modeRightInfo.editModeDataShare(1, Integer.parseInt(modeId), Integer.parseInt(cusId));
        } catch (Exception e) {
            baseBean.writeLog("countIndexScoring error:" + e);
            result.put("mes", "系统错误，请联系管理员！");
            result.put("code", "400");
            return result;
        }
        baseBean.writeLog("countIndexScoring end.");
        result.put("mes", "正在计算，请稍等！");
        result.put("code", "200");
        return result;
    }

    public void handleJxAgain(String khjh, Set<String> zbSet, Set<String> protectSet, Set<String> aboveOneGwSet) {
        baseBean.writeLog("handleJxAgain start.");
        RecordSet rs = new RecordSet();
        // 计分规则-越来越高id
        String ruleHigherId = rs.getPropValue("qz_jx_zm_prop", "jf_rule_higher_id");
        // 计分规则-越来越低id
        String ruleLowerId = rs.getPropValue("qz_jx_zm_prop", "jf_rule_lower_id");
        // 计分规则-计次不占权重id
        String rule3 = rs.getPropValue("qz_jx_zm_prop", "jf_rule_count_without_weighting_id");
        // 计分规则-以完成值作为得分id
        String rule4 = rs.getPropValue("qz_jx_zm_prop", "jf_rule_base_complete_id");
        // 计分规则-完成值区间固定得分id
        String rule5 = rs.getPropValue("qz_jx_zm_prop", "jf_rule_complete_interval_id");
        RecordSet rs1 = new RecordSet();
        Map<String, String> dfMap = new HashMap<>();
        Map<String, String> bzjxxsMap = new HashMap<>();
        Map<String, List<Map<String, String>>> dfMainMap = new HashMap<>();

        String sqlT = "select a.id, a.zb, a.df as dtdf, a.mainid, b.df, b.yg, b.khfa from uf_jxdfjgb_dt1 a, uf_jxdfjgb b where a.mainid = b.id and b.khjh = " +
                khjh + " and a.zb in (" + String.join(",", zbSet) + ")";
        baseBean.writeLog("handleJxAgain sql:" + sqlT);
        Map<String, String> dtIdMap = new HashMap<>();
        Map<String, String> zbIdMap = new HashMap<>();
        Map<String, String> sfscMap = new HashMap<>();
        rs.execute(sqlT);
        while (rs.next()) {
            String zb = rs.getString("zb");
            String id = rs.getString("id");
            String mainid = rs.getString("mainid");
            String yg = rs.getString("yg");
            String df = rs.getString("df");
            String dtdf = rs.getString("dtdf");
            String khfa = rs.getString("khfa");
            if (StringUtils.isEmpty(zb) || StringUtils.isEmpty(id) || StringUtils.isEmpty(mainid) || StringUtils.isEmpty(yg) || StringUtils.isEmpty(khfa)) {
                continue;
            }
            if (StringUtils.isEmpty(df)) {
                df = "0";
            }
            if (StringUtils.isEmpty(dtdf)) {
                dtdf = "0";
            }
            String mainDf = "0";
            BigDecimal dfBd = new BigDecimal(df);
            if (dfBd.compareTo(BigDecimal.ZERO) > 0) {
                dfBd = dfBd.subtract(new BigDecimal(dtdf));
            }
            if (dfBd.compareTo(BigDecimal.ZERO) == 0) {
                mainDf = "0";
            } else {
                mainDf = dfBd.toString();
            }
            zbIdMap.put(yg + "_" + khjh + "_" + khfa, mainid + "_" + mainDf);
            dtIdMap.put(yg + "_" + khjh + "_" + khfa + "_" + zb, id);
        }

        List<List> updateListB = new ArrayList<>();

        rs.execute("SELECT t1.*, t2.szny, t4.workcode, t3.wcz, t5.qzfbpxyxj, t6.jxxssx, t6.jxxsxx FROM " +
                " (SELECT a.*, b.szkhjh, b.szkhfa, b.sfscbzjxxs, b.yg from uf_ygmxzbdy_dt1 a, uf_ygmxzbdy b WHERE a.mainid = b.id" +
                " AND b.szkhjh = " + khjh + ") t1 LEFT JOIN uf_khjhdy t2 on t1.szkhjh = t2.id " +
                " LEFT JOIN hrmresource t4 on t1.yg = t4.id " +
                " LEFT JOIN uf_zbk t5 on t1.zbid = t5.id " +
                " LEFT JOIN uf_bzkhfa t6 on t1.szkhfa = t6.id " +
                " LEFT JOIN uf_wczjgb t3 on t1.zbid = t3.zbid and t2.szny = t3.szny and t4.workcode = t3.yggh");

        while (rs.next()) {
            String id = rs.getString("id");
            String yg = rs.getString("yg");
            String szkhjh = rs.getString("szkhjh");
            String szkhfa = rs.getString("szkhfa");
            String zbid = rs.getString("zbid");
            String qzfbpxyxj = rs.getString("qzfbpxyxj");
            String jxxssx = rs.getString("jxxssx");
            String jxxsxx = rs.getString("jxxsxx");
            String x1 = rs.getString("x1");
            String x2 = rs.getString("x2");
            String x3 = rs.getString("x3");
            String x4 = rs.getString("x4");
            String x5 = rs.getString("x5");
            String n1 = rs.getString("n1");
            String n2 = rs.getString("n2");
            String n3 = rs.getString("n3");
            String n4 = rs.getString("n4");
            String n5 = rs.getString("n5");
            String n6 = rs.getString("n6");
            String wcz = rs.getString("wcz");
            String bdz = rs.getString("bdz");
            String mbz = rs.getString("mbz");
            String tzz = rs.getString("tzz");
            String jfgzid = rs.getString("jfgzid");
            String zbqz = rs.getString("zbqz");
            String jckfxs = rs.getString("jckfxs");
            String sfscbzjxxs = rs.getString("sfscbzjxxs");
            if (StringUtils.isEmpty(zbid) || !zbSet.contains(zbid)) {
                continue;
            }
            if (StringUtils.isEmpty(jfgzid) || StringUtils.isEmpty(yg) || StringUtils.isEmpty(szkhfa) || StringUtils.isEmpty(szkhjh)) {
                continue;
            }

            boolean isGoingA = true;
            boolean isGoingB = true;
            if (StringUtils.equals(jfgzid, ruleHigherId) || StringUtils.equals(jfgzid, ruleLowerId)) {
                if (StringUtils.isEmpty(bdz) || StringUtils.isEmpty(mbz) || StringUtils.isEmpty(tzz)) {
                    isGoingA = false;
                }
            }
            if (StringUtils.equals(jfgzid, rule5) && (StringUtils.isEmpty(x1) || StringUtils.isEmpty(x2) || StringUtils.isEmpty(x3) || StringUtils.isEmpty(x4)
                    || StringUtils.isEmpty(x5) || StringUtils.isEmpty(n1) || StringUtils.isEmpty(n2) || StringUtils.isEmpty(n3) ||
                    StringUtils.isEmpty(n4) || StringUtils.isEmpty(n5) || StringUtils.isEmpty(n6))) {
                isGoingB = false;
            }
            if (StringUtils.isEmpty(zbqz)) {
                zbqz = "0";
            }
            if (StringUtils.isEmpty(jckfxs)) {
                jckfxs = "0";
            }
            String df = null;
            if (StringUtils.isNotEmpty(wcz) && isGoingA && isGoingB) {
                BigDecimal wczBd = new BigDecimal(wcz);

                if (StringUtils.equals(jfgzid, ruleHigherId)) {
                    BigDecimal bdzBd = new BigDecimal(bdz);
                    BigDecimal mbzBd = new BigDecimal(mbz);
                    BigDecimal tzzBd = new BigDecimal(tzz);
                    if (wczBd.compareTo(bdzBd) < 0) {
                        df = "0";
                    } else if (wczBd.compareTo(bdzBd) >= 0 && wczBd.compareTo(mbzBd) < 0) {
                        BigDecimal dfBd = ((wczBd.subtract(bdzBd)).divide((mbzBd.subtract(bdzBd)), 8, RoundingMode.HALF_UP))
                                .multiply(new BigDecimal(zbqz));
                        if (dfBd.compareTo(BigDecimal.ZERO) == 0) {
                            df = "0";
                        } else {
                            df = dfBd.toString();
                        }
                    } else if (wczBd.compareTo(mbzBd) >= 0 && wczBd.compareTo(tzzBd) < 0) {
                        BigDecimal dfBd = (((wczBd.subtract(mbzBd)).divide((tzzBd.subtract(mbzBd)), 8, RoundingMode.HALF_UP))
                                .add(new BigDecimal("1"))).multiply(new BigDecimal(zbqz));
                        if (dfBd.compareTo(BigDecimal.ZERO) == 0) {
                            df = "0";
                        } else {
                            df = dfBd.toString();
                        }
                    } else if (wczBd.compareTo(tzzBd) >= 0) {
                        df = new BigDecimal("200").multiply(new BigDecimal(zbqz)).toString();
                    }
                } else if (StringUtils.equals(jfgzid, ruleLowerId)) {
                    BigDecimal bdzBd = new BigDecimal(bdz);
                    BigDecimal mbzBd = new BigDecimal(mbz);
                    BigDecimal tzzBd = new BigDecimal(tzz);
                    if (wczBd.compareTo(bdzBd) > 0) {
                        df = "0";
                    } else if (wczBd.compareTo(bdzBd) <= 0 && wczBd.compareTo(mbzBd) > 0) {
                        BigDecimal dfBd = ((wczBd.subtract(bdzBd)).divide((mbzBd.subtract(bdzBd)), 8, RoundingMode.HALF_UP))
                                .multiply(new BigDecimal(zbqz));
                        if (dfBd.compareTo(BigDecimal.ZERO) == 0) {
                            df = "0";
                        } else {
                            df = dfBd.toString();
                        }
                    } else if (wczBd.compareTo(mbzBd) <= 0 && wczBd.compareTo(tzzBd) > 0) {
                        BigDecimal dfBd = (((wczBd.subtract(mbzBd)).divide((tzzBd.subtract(mbzBd)), 8, RoundingMode.HALF_UP))
                                .add(new BigDecimal("1"))).multiply(new BigDecimal(zbqz));
                        if (dfBd.compareTo(BigDecimal.ZERO) == 0) {
                            df = "0";
                        } else {
                            df = dfBd.toString();
                        }
                    } else if (wczBd.compareTo(tzzBd) < 0) {
                        df = new BigDecimal("200").multiply(new BigDecimal(zbqz)).toString();
                    }
                } else if (StringUtils.equals(jfgzid, rule3)) {
                    BigDecimal dfBd = wczBd.multiply(new BigDecimal(jckfxs));
                    if (dfBd.compareTo(BigDecimal.ZERO) == 0) {
                        df = "0";
                    } else {
                        df = dfBd.toString();
                    }
                } else if (StringUtils.equals(jfgzid, rule4)) {
                    df = wcz;
                } else if (StringUtils.equals(jfgzid, rule5)) {
                    BigDecimal x1Bd = new BigDecimal(x1);
                    BigDecimal x2Bd = new BigDecimal(x2);
                    BigDecimal x3Bd = new BigDecimal(x3);
                    BigDecimal x4Bd = new BigDecimal(x4);
                    BigDecimal x5Bd = new BigDecimal(x5);
                    if (wczBd.compareTo(x1Bd) < 0) {
                        df = n1;
                    } else if (wczBd.compareTo(x1Bd) >= 0 && wczBd.compareTo(x2Bd) < 0) {
                        df = n2;
                    } else if (wczBd.compareTo(x2Bd) >= 0 && wczBd.compareTo(x3Bd) < 0) {
                        df = n3;
                    } else if (wczBd.compareTo(x3Bd) >= 0 && wczBd.compareTo(x4Bd) < 0) {
                        df = n4;
                    } else if (wczBd.compareTo(x4Bd) >= 0 && wczBd.compareTo(x5Bd) < 0) {
                        df = n5;
                    } else if (wczBd.compareTo(x5Bd) >= 0) {
                        df = n6;
                    }
                }
            }
            if (StringUtils.isEmpty(df) || new BigDecimal(df).compareTo(BigDecimal.ZERO) == 0) {
                df = "0";
            }
            baseBean.writeLog("countIndexScoring df:" + df + "、" + id);
            rs1.executeUpdate("UPDATE uf_ygmxzbdy_dt1 SET df = ? WHERE id = ?", df, id);

            String key = yg + "-" + szkhjh + "-" + szkhfa;
            if ((!CollectionUtils.isEmpty(dfMap)) && dfMap.containsKey(key)) {
                String dfInt = dfMap.get(key);
                if (StringUtils.isEmpty(dfInt)) {
                    dfInt = "0";
                }
                dfMap.put(key, new BigDecimal(df).add(new BigDecimal(dfInt)).toString());
            } else {
                dfMap.put(key, df);
            }
            bzjxxsMap.put(key, jxxssx + "_" + jxxsxx);
            sfscMap.put(key, sfscbzjxxs);

            String newKey = yg + "-" + szkhjh + "-" + szkhfa + "_" + zbid;
            String mxId = dtIdMap.get(newKey);
            if (StringUtils.isNotEmpty(mxId)) {
                List arrayListB = new ArrayList<>();
                arrayListB.add(df);
                arrayListB.add(wcz);
                arrayListB.add(mbz);
                arrayListB.add(mxId);
                updateListB.add(arrayListB);
            }
        }

        if (CollectionUtils.isEmpty(dfMap)) {
            baseBean.writeLog("handleJxAgain dfMap is null.");
        } else {
            baseBean.writeLog("handleJxAgain dfMap size is:" + dfMap.size());
        }
        if (!CollectionUtils.isEmpty(dfMap)) {
            List<List> updateListA = new ArrayList<>();
            for (Map.Entry<String, String> entry : dfMap.entrySet()) {
                String key = entry.getKey();
                String value1 = entry.getValue();
                if (StringUtils.isEmpty(value1)) {
                    value1 = "0";
                }
                String value = zbIdMap.get(key);
                if (StringUtils.isEmpty(value)) {
                    continue;
                }
                if (value.split("_").length < 2) {
                    continue;
                }
                String zbId = value.split("_")[0];
                if (StringUtils.isEmpty(zbId)) {
                    continue;
                }

                String zbDf = value.split("_")[1];
                if (StringUtils.isEmpty(zbDf)) {
                    zbDf = "0";
                }
                BigDecimal dfValueBd = new BigDecimal(zbDf).add(new BigDecimal(value1));
                BigDecimal bzjxxs = dfValueBd.divide(new BigDecimal("100"), 2, RoundingMode.HALF_UP);

                String jxxssx = "0";
                String jxxsxx = "0";
                String sxxStr = bzjxxsMap.get(key);
                if (StringUtils.isNotEmpty(sxxStr) && sxxStr.split("_").length == 2) {
                    jxxssx = sxxStr.split("_")[0];
                    jxxsxx = sxxStr.split("_")[1];
                }
                if (bzjxxs.compareTo(new BigDecimal(jxxssx)) > 0) {
                    bzjxxs = new BigDecimal(jxxssx);
                }
                if (bzjxxs.compareTo(new BigDecimal(jxxsxx)) < 0) {
                    bzjxxs = new BigDecimal(jxxsxx);
                }
                if (bzjxxs.compareTo(BigDecimal.ZERO) == 0) {
                    bzjxxs = new BigDecimal("0");
                }

                String yg = key.split("_")[0];
                String sfwbhq = "1";
                if ((!CollectionUtils.isEmpty(protectSet)) && protectSet.contains(yg)) {
                    bzjxxs = new BigDecimal("1");
                    sfwbhq = "0";
                }
                if ((!CollectionUtils.isEmpty(aboveOneGwSet)) && aboveOneGwSet.contains(yg) && bzjxxs.compareTo(new BigDecimal("1")) < 0) {
                    bzjxxs = new BigDecimal("1");
                }
                String sfsc = sfscMap.get(key);
                if (StringUtils.isEmpty(sfsc)) {
                    sfsc = "0";
                }
                if (new BigDecimal(sfsc).compareTo(new BigDecimal("1")) == 0) {
                    bzjxxs = new BigDecimal("0");
                }

                List arrayListA = new ArrayList<>();
                arrayListA.add(dfValueBd.toString());
                arrayListA.add(bzjxxs.toString());
                arrayListA.add(sfwbhq);
                arrayListA.add(sfsc);
                arrayListA.add(zbId);
                updateListA.add(arrayListA);
            }
            if (!CollectionUtils.isEmpty(updateListA)) {
                String updateSqlA = "UPDATE uf_jxdfjgb SET df = ?, bzjxxs = ?, sfwbhq = ?, sfscbzjxxs = ? WHERE id = ?";
                rs.executeBatchSql(updateSqlA, updateListA);
            }

            if (!CollectionUtils.isEmpty(updateListB)) {
                String updateSqlB = "UPDATE uf_jxdfjgb_dt1 SET df = ?, wcz = ?, bzz = ? WHERE id = ?";
                rs.executeBatchSql(updateSqlB, updateListB);
            }
        }
        baseBean.writeLog("handleJxAgain end.");
    }

    @Override
    public Map<String, Object> countWcz(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        baseBean.writeLog("countWcz start:" + params);
        try {
            // 考核计划
            String khjh = Util.null2String(params.get("khjh"));
            if (StringUtils.isEmpty(khjh)) {
                baseBean.writeLog("countWcz khjh is null.");
                result.put("mes", "请选择考核计划！");
                result.put("code", "200");
                return result;
            }

            RecordSet rs = new RecordSet();
            // 获取考核计划所属年月
            String jhSzny = null;
            rs.execute("SELECT szny FROM uf_khjhdy WHERE id = " + khjh);
            if (rs.next()) {
                jhSzny = rs.getString("szny");
            }
            if (StringUtils.isEmpty(jhSzny)) {
                baseBean.writeLog("countWcz jhSzny is null.");
                result.put("mes", "该考核计划所属年月获取失败，请检查！");
                result.put("code", "200");
                return result;
            }

            // 更新完成值结果表
            updateWczjgData(jhSzny);
        } catch (Exception e) {
            baseBean.writeLog("countWcz error:" + e);
            result.put("mes", "系统错误，请联系管理员！");
            result.put("code", "400");
            return result;
        }
        baseBean.writeLog("countWcz end.");
        result.put("mes", "正在计算，请稍等！");
        result.put("code", "200");
        return result;
    }

    @Override
    public Map<String, Object> distributeCount(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        baseBean.writeLog("distributeCount start:" + params);
        try {
            // 考核计划
            String khjh = Util.null2String(params.get("khjh"));
            if (StringUtils.isEmpty(khjh)) {
                baseBean.writeLog("distributeCount khjh is null.");
                result.put("mes", "请选择考核计划！");
                result.put("code", "200");
                return result;
            }
            // 强制分布方案
            String qzfbfa = Util.null2String(params.get("qzfbfa"));
            if (StringUtils.isEmpty(qzfbfa)) {
                baseBean.writeLog("distributeCount qzfbfa is null.");
                result.put("mes", "请选择分布方案！");
                result.put("code", "200");
                return result;
            }
            RecordSet rs = new RecordSet();
            RecordSet rs1 = new RecordSet();
            // 获取考核计划所属年月
            String szny = null;
            rs.execute("select szny from uf_khjhdy where id = " + khjh);
            if (rs.next()) {
                szny = rs.getString("szny");
            }
            if (StringUtils.isEmpty(szny)) {
                baseBean.writeLog("distributeCount szny is null.");
                result.put("mes", "考核计划所属周期获取失败，请检查！");
                result.put("code", "200");
                return result;
            }
            // 首先删除考核计划和强制分布方案对应的数据
            rs.execute("DELETE FROM uf_ygdjfbjl WHERE khjh = " + khjh + " AND qzfbfa = " + qzfbfa);

            // 定义一个DateTimeFormatter对象，用于解析年月字符串
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
            // 将字符串解析为YearMonth对象
            YearMonth yearMonth = YearMonth.parse(szny, formatter);
            // 从YearMonth对象中提取年份与月份
            int year = yearMonth.getYear();
            int month = yearMonth.getMonthValue();

            // 获取保护期人员
            Set<String> protectSet = new HashSet<>();
            rs.executeQuery("SELECT ygxm FROM uf_khbhqxxrg WHERE lx = 1 AND ((YEAR(CONVERT(date, ksrq)) = ? AND MONTH(CONVERT(date, ksrq)) = ?)" +
                    " OR (YEAR(CONVERT(date, jsrq)) = ? AND MONTH(CONVERT(date, jsrq)) = ?))", year, month, year, month);
            while (rs.next()) {
                String ygxm = rs.getString("ygxm");
                if (StringUtils.isNotEmpty(ygxm)) {
                    protectSet.add(ygxm);
                }
            }

            // 岗位fieldId 3
            String gwFieldId = rs.getPropValue("qz_jx_zm_prop", "gw_field_id");
            // 职级fieldId 3
            String zjFieldId = rs.getPropValue("qz_jx_zm_prop", "zj_field_id");

            // 获取强制分布方案
            String xtdfpxlj = null;
            String ryfw = null;
            rs.execute("(SELECT ryfw,xtdfpxlj FROM uf_djfblj WHERE id = " + qzfbfa + ")");
            if (rs.next()) {
                ryfw = rs.getString("ryfw");
                xtdfpxlj = rs.getString("xtdfpxlj");
            }
            if (StringUtils.isEmpty(ryfw)) {
                baseBean.writeLog("distributeCount ryfw is null.");
                result.put("mes", "请设置强制分布方案中的人员范围！");
                result.put("code", "200");
                return result;
            }
            // 获取分布方案人员范围
            Set<String> ryfwSet = new HashSet<>();
            rs.execute("select * from uf_jxpmfa where id =  " + ryfw);
            if (rs.next()) {
                String gw = rs.getString("gw");
                String fs = rs.getString("fs");
                String fslb = rs.getString("fslb");
                String gdry = rs.getString("gdry");
                String zwxl = rs.getString("zwxl");
                String zj = rs.getString("zj");
                String sfbhq = rs.getString("sfbhq");

                String sqlA = "SELECT a.id, b." + gwFieldId + " as gw, a.subcompanyid1, b." + zjFieldId + " as zj from hrmresource a " +
                        " LEFT JOIN cus_fielddata b ON a.id = b.id and b.scope = 'HrmCustomFieldByInfoType' and scopeid = 3 " +
                        " WHERE a.status in (0,1,2,3) ";
                if (StringUtils.isNotEmpty(fs)) {
                    sqlA = sqlA + " AND a.subcompanyid1 in (" + fs + ") ";
                }
                if (StringUtils.isNotEmpty(gdry)) {
                    sqlA = sqlA + " AND a,id in (" + gdry + ") ";
                }
                if (StringUtils.isNotEmpty(fslb)) {
                    sqlA = sqlA + " AND a.subcompanyid1 in (SELECT fb from uf_yjtl WHERE lb in (" + fslb + ")) ";
                }
                Set<String> gwSet = new HashSet<>();
                if (StringUtils.isNotEmpty(zwxl)) {
                    String xl = "P";
                    if (StringUtils.equals(zwxl, "1")) {
                        xl = "M";
                    }
                    rs1.executeQuery("select id from uf_JCL_GWGL where szzwxl in (select id from uf_zwxl where xlbm = ?)", xl);
                    while (rs1.next()) {
                        String idT = rs1.getString("id");
                        if (StringUtils.isEmpty(idT)) {
                            continue;
                        }
                        gwSet.add(idT);
                    }
                }

                Set<String> gwSetNew = new HashSet<>();
                if (StringUtils.isNotEmpty(gw)) {
                    String[] gwmcArr = gw.split("；");
                    String gwmcSql = "SELECT id FROM uf_JCL_GWGL ";
                    for (int i = 0; i < gwmcArr.length; i++) {
                        if (i == 0) {
                            gwmcSql = gwmcSql + " WHERE gwmc LIKE '%" + gwmcArr[i] + "%' ";
                        } else {
                            gwmcSql = gwmcSql + " OR gwmc LIKE '%" + gwmcArr[i] + "%' ";
                        }
                    }

                    rs1.execute(gwmcSql);
//                    rs1.execute("select id from uf_JCL_GWGL where gwmc like '%" + gw + "%'");
                    while (rs1.next()) {
                        String id = rs1.getString("id");
                        if (StringUtils.isNotEmpty(id)) {
                            gwSetNew.add(id);
                        }
                    }
                }
                baseBean.writeLog("distributeCount sqlA:" + sqlA);
                rs1.execute(sqlA);
                while (rs1.next()) {
                    String id = rs1.getString("id");
                    String gwT = rs1.getString("gw");
                    String zjT = rs1.getString("zj");
                    if (StringUtils.isNotEmpty(gw)) {
                        if (CollectionUtils.isEmpty(gwSetNew) || !gwSetNew.contains(gwT)) {
                            continue;
                        }
                    }
                    if (StringUtils.isNotEmpty(zwxl)) {
                        if (CollectionUtils.isEmpty(gwSet) || !gwSet.contains(gwT)) {
                            continue;
                        }
                    }
                    if (StringUtils.isNotEmpty(zj)) {
                        List<String> list = Arrays.asList(zj.split(","));
                        if (!list.contains(zjT)) {
                            continue;
                        }
                    }
                    if (StringUtils.equals(sfbhq, "0")) {
                        if (CollectionUtils.isEmpty(protectSet) || !protectSet.contains(id)) {
                            continue;
                        }
                    }
                    if (StringUtils.equals(sfbhq, "1")) {
                        if ((!CollectionUtils.isEmpty(protectSet)) && protectSet.contains(id)) {
                            continue;
                        }
                    }
                    ryfwSet.add(id);
                }
//                if (StringUtils.isEmpty(gw) && StringUtils.isEmpty(fs) && StringUtils.isEmpty(fslb) && StringUtils.isEmpty(gdry) &&
//                        StringUtils.isEmpty(zwxl) && StringUtils.isEmpty(zj) && StringUtils.isEmpty(sfbhq)) {
//                    baseBean.writeLog("distributeCount ryfw is null.");
//                    result.put("mes", "考核计划所属周期获取失败，请检查！");
//                    result.put("code", "200");
//                    return result;
//                }
            }

            if (CollectionUtils.isEmpty(ryfwSet)) {
                baseBean.writeLog("distributeCount ryfwSet is null.");
                result.put("mes", "人员范围获取失败！");
                result.put("code", "200");
                return result;
            }


            String querySqlDf = "SELECT * FROM uf_jxdfjgb WHERE khjh = ? AND df is not null ORDER BY df DESC";
            baseBean.writeLog("distributeCount xtdfpxlj is:" + xtdfpxlj);
            if (StringUtils.equals(xtdfpxlj, "2")) {
                querySqlDf = "SELECT * FROM uf_jxdfjgb WHERE khjh = ? AND df is not null ORDER BY df DESC, wcl DESC";
            }

            List<Map<String, String>> mapList = new ArrayList<>();
            Map<String, Map<String, String>> mapListMapAll = new HashMap<>();

            String oldDf = "-1";
            String oldId = "0";
            Map<String, String> orderIdMap = new HashMap<>();
            List<Set<String>> setList = new ArrayList<>();
            Set<String> sameList = new HashSet<>();
            int idCnt = 0;
            rs.executeQuery(querySqlDf, khjh);
            while (rs.next()) {
                String id = rs.getString("id");
                String khjhT = rs.getString("khjh");
                String yg = rs.getString("yg");
                if (!ryfwSet.contains(yg)) {
                    continue;
                }
                String df = rs.getString("df");
                String khfa = rs.getString("khfa");
                if (StringUtils.isEmpty(df)) {
                    df = "0";
                }
                if (new BigDecimal(oldDf).compareTo(new BigDecimal(df)) == 0) {

                    sameList.add(oldId);
                    sameList.add(id);
                } else {
                    if (!CollectionUtils.isEmpty(sameList)) {
                        setList.add(sameList);
                        sameList = new HashSet<>();
                    }
                }
                oldDf = df;
                oldId = id;

                Map<String, String> mapTemp = new HashMap<>();
                mapTemp.put("id", id);
                mapTemp.put("khjh", khjhT);
                mapTemp.put("yg", yg);
                mapTemp.put("df", df);
                mapTemp.put("szny", szny);
                mapTemp.put("khfa", khfa);
                if ((!CollectionUtils.isEmpty(protectSet)) && protectSet.contains(yg)) {
                    mapTemp.put("isProtect", "1");
                } else {
                    mapTemp.put("isProtect", "0");
                }
                mapList.add(mapTemp);
                orderIdMap.put(id, String.valueOf(idCnt));
                mapListMapAll.put(id, mapTemp);
                idCnt = idCnt + 1;
            }
            if (CollectionUtils.isEmpty(mapList)) {
                baseBean.writeLog("distributeCount mapList is null.");
                result.put("mes", "该考核计划无员工得分数据！");
                result.put("code", "200");
                return result;
            }

            baseBean.writeLog("distributeCount mapList A is:" + mapList);

            if (StringUtils.equals(xtdfpxlj, "0") || StringUtils.equals(xtdfpxlj, "1")) {
                if (!CollectionUtils.isEmpty(setList)) {
                    baseBean.writeLog("distributeCount setList is:" + setList);
                } else {
                    baseBean.writeLog("distributeCount is null.");
                }
                // 首先获取强制分布方案中若得分一样的排序逻辑
                if (!CollectionUtils.isEmpty(setList)) {
                    String sqlA = "SELECT id, mainid, zb, zbqz, df, bzz, wcz, yxj, ROW_NUMBER() OVER (PARTITION BY mainid ORDER BY yxj) AS  RowNum\n" +
                            " FROM uf_jxdfjgb_dt1 ";
                    Map<String, List<Map<String, String>>> mapListMap = new HashMap<>();
                    rs.execute(sqlA);
                    while (rs.next()) {
                        String mainid = rs.getString("mainid");
                        String zb = rs.getString("zb");
                        String zbqz = rs.getString("zbqz");
                        String df = rs.getString("df");
                        String bzz = rs.getString("bzz");
                        String wcz = rs.getString("wcz");
                        String yxj = rs.getString("yxj");
                        Map<String, String> mainMapTemp = new HashMap<>();
                        mainMapTemp.put("mainid", mainid);
                        mainMapTemp.put("zb", zb);
                        mainMapTemp.put("zbqz", zbqz);
                        mainMapTemp.put("df", df);
                        mainMapTemp.put("bzz", bzz);
                        mainMapTemp.put("wcz", wcz);
                        mainMapTemp.put("yxj", yxj);
                        List<Map<String, String>> mapListMain = new ArrayList<>();
                        if ((!CollectionUtils.isEmpty(mapListMap)) && mapListMap.containsKey(mainid)) {
                            mapListMain = mapListMap.get(mainid);
                        }
                        mapListMain.add(mainMapTemp);
                        mapListMap.put(mainid, mapListMain);
                    }

                    for (Set<String> setIds : setList) {
                        Map<String, Integer> idOrderMap = new HashMap<>();
                        if (StringUtils.equals(xtdfpxlj, "0")) {
                            List<List<Map<String, String>>> mapListList = new ArrayList<>();
                            for (String idA : setIds) {
                                String rankStr = orderIdMap.get(idA);
                                if (StringUtils.isEmpty(rankStr)) {
                                    rankStr = "0";
                                }
                                idOrderMap.put(idA, Integer.parseInt(rankStr));
                                List<Map<String, String>> mapList1 = mapListMap.get(idA);
                                // 插入排序
                                if (!CollectionUtils.isEmpty(mapListList)) {
                                    for (int i = 0; i < mapListList.size(); i++) {
                                        List<Map<String, String>> mapList2 = mapListList.get(i);
                                        int size = mapList2.size();
                                        int size1 = mapList1.size();
                                        boolean isSkip = false;
                                        int endIndex = size;
                                        if (size <= size1) {
                                            endIndex = size1;
                                        }
                                        for (int j = 0; j < endIndex; j++) {
                                            if (size1 > size) {
                                                if (j >= size) {
                                                    isSkip = true;
                                                    mapListList.add(i, mapList1);
                                                    break;
                                                }
                                            }
                                            if (size1 < size) {
                                                if (j >= size1) {
                                                    isSkip = true;
                                                    mapListList.add(mapList1);
                                                    break;
                                                }
                                            }
                                            Map<String, String> map2 = mapList2.get(j);
                                            Map<String, String> map1 = mapList1.get(j);
                                            String zbYxj2 = map2.get("yxj");
                                            String zbYxj1 = map1.get("yxj");
                                            if (StringUtils.isEmpty(zbYxj2)) {
                                                zbYxj2 = "0";
                                            }
                                            if (StringUtils.isEmpty(zbYxj1)) {
                                                zbYxj1 = "0";
                                            }
                                            if (new BigDecimal(zbYxj1).compareTo(new BigDecimal(zbYxj2)) == 0) {
                                                String df2 = map2.get("df");
                                                if (StringUtils.isEmpty(df2)) {
                                                    df2 = "0";
                                                }
                                                String df1 = map1.get("df");
                                                if (StringUtils.isEmpty(df1)) {
                                                    df1 = "0";
                                                }
                                                BigDecimal df1Bg = new BigDecimal(df1);
                                                BigDecimal df2Bg = new BigDecimal(df2);
                                                if (df1Bg.compareTo(df2Bg) == 0) {
                                                    if (j == endIndex - 1) {
                                                        isSkip = true;
                                                        mapListList.add(mapList1);
                                                        break;
                                                    }
                                                } else if (df1Bg.compareTo(df2Bg) > 0) {
                                                    mapListList.add(i, mapList1);
                                                    isSkip = true;
                                                    break;
                                                } else {
                                                    isSkip = true;
                                                    mapListList.add(mapList1);
                                                    break;
                                                }
                                            } else if (new BigDecimal(zbYxj1).compareTo(new BigDecimal(zbYxj2)) < 0) {
                                                mapListList.add(i, mapList1);
                                                isSkip = true;
                                                break;
                                            } else {
                                                isSkip = true;
                                                mapListList.add(mapList1);
                                                break;
                                            }
                                        }
                                        if (isSkip) {
                                            break;
                                        }
                                    }
                                } else {
                                    mapListList.add(mapList1);
                                }
                            }

                            List<Integer> sortedValues = idOrderMap.values().stream()
                                    .sorted() // 使用自然顺序排序
                                    .collect(Collectors.toList());

                            for (int i = 0; i < mapListList.size(); i++) {
                                String mainid = mapListList.get(i).get(0).get("mainid");
                                Integer sortedValue = sortedValues.get(i);
                                if (sortedValue == null) {
                                    sortedValue = 0;
                                }
                                orderIdMap.put(mainid, String.valueOf(sortedValue));
                            }
                        }
                        if (StringUtils.equals(xtdfpxlj, "1")) {
                            List<Map<String, String>> mapListOne = new ArrayList<>();
                            for (String idA : setIds) {
                                String rankStr = orderIdMap.get(idA);
                                if (StringUtils.isEmpty(rankStr)) {
                                    rankStr = "0";
                                }
                                idOrderMap.put(idA, Integer.parseInt(rankStr));
                                List<Map<String, String>> mapList1 = mapListMap.get(idA);
                                String dfCnt = "0";
                                for (Map<String, String> map : mapList1) {
                                    String wcz = map.get("wcz");
                                    String bzz = map.get("bzz");
                                    String zbqz = map.get("zbqz");
                                    if (StringUtils.isEmpty(bzz)) {
                                        bzz = "0";
                                    }
                                    if (StringUtils.isEmpty(zbqz)) {
                                        zbqz = "0";
                                    }
                                    if (StringUtils.isEmpty(wcz)) {
                                        wcz = "0";
                                    }
                                    if (new BigDecimal(bzz).compareTo(BigDecimal.ZERO) != 0) {
                                        dfCnt = (new BigDecimal(wcz).divide(new BigDecimal(bzz), 8, RoundingMode.HALF_UP).multiply(new BigDecimal(zbqz))).add(new BigDecimal(dfCnt)).toString();
                                    }
                                }
                                Map<String, String> mapOne = new HashMap<>();
                                mapOne.put("idA", idA);
                                mapOne.put("dfCnt", dfCnt);
                                // 插入排序
                                if (!CollectionUtils.isEmpty(mapListOne)) {
                                    for (int i = 0; i < mapListOne.size(); i++) {
                                        Map<String, String> map = mapListOne.get(i);
                                        String value = map.get("dfCnt");
                                        if (StringUtils.isEmpty(value)) {
                                            value = "0";
                                        }
                                        if (new BigDecimal(dfCnt).compareTo(new BigDecimal(value)) > 0) {
                                            mapListOne.add(i, mapOne);
                                            break;
                                        } else {
                                            if (i == mapListOne.size() - 1) {
                                                mapListOne.add(mapOne);
                                                break;
                                            }
                                        }
                                    }
                                } else {
                                    mapListOne.add(mapOne);
                                }
                            }
                            List<Integer> sortedValues = idOrderMap.values().stream()
                                    .sorted() // 使用自然顺序排序
                                    .collect(Collectors.toList());
                            for (int i = 0; i < mapListOne.size() - 1; i++) {
                                String idA = mapListOne.get(i).get("idA");
                                Integer sortedValue = sortedValues.get(i);
                                if (sortedValue == null) {
                                    sortedValue = 0;
                                }
                                orderIdMap.put(idA, String.valueOf(sortedValue));
                            }
                        }
                    }
                }

                // 使用Comparator.comparingInt()将字符串值转换为整数并比较
                Comparator<Map.Entry<String, String>> byValue = Comparator
                        .comparingInt(entry -> Integer.parseInt(entry.getValue()));

                // 将Map转换为List<Map.Entry<String, String>>，并根据自定义比较器排序
                List<Map.Entry<String, String>> sortedEntries = orderIdMap.entrySet().stream()
                        .sorted(byValue)
                        .collect(Collectors.toList());

                mapList = new ArrayList<>();
                for (Map.Entry<String, String> entry : sortedEntries) {
                    mapList.add(mapListMapAll.get(entry.getKey()));
                }
            }

            baseBean.writeLog("distributeCount mapList B is:" + mapList);

            if (CollectionUtils.isEmpty(mapList)) {
                baseBean.writeLog("distributeCount mapList new is null.");
                result.put("mes", "该考核计划无员工得分数据！");
                result.put("code", "200");
                return result;
            }

            baseBean.writeLog("start to query uf_djfblj.");

            // 获取强制分布方案
            String querySql = "SELECT a.*, b.sfsy, b.ryfw, b.djmc  FROM uf_djfblj_dt1 a, uf_djfblj b WHERE a.mainid = b.id " +
                    " AND b.id = ? ORDER BY a.yxj";
            // 是否顺延 0：是  1：否
            String sfsy = null;
            int startIndex = 0;
            rs.executeQuery(querySql, qzfbfa);
            while (rs.next()) {
                int size = mapList.size();
                if (startIndex >= size) {
                    continue;
                }
                String djmc = rs.getString("djmc");
                String bl = rs.getString("bl");
                String qzfs = rs.getString("qzfs");
                String jcje = rs.getString("jcje");
                sfsy = rs.getString("sfsy");
                if (StringUtils.isEmpty(bl)) {
                    bl = "0";
                }

                int rsCnt = 0;
                if (StringUtils.equals(qzfs, "0")) {
                    rsCnt = new BigDecimal(String.valueOf(size)).multiply(new BigDecimal(bl)).multiply(new BigDecimal("100"))
                            .divide(new BigDecimal("100"), RoundingMode.UP).intValue();
                } else if (StringUtils.equals(qzfs, "1")) {
                    rsCnt = new BigDecimal(String.valueOf(size)).multiply(new BigDecimal(bl)).multiply(new BigDecimal("100"))
                            .divide(new BigDecimal("100"), RoundingMode.DOWN).intValue();
                } else {
                    rsCnt = new BigDecimal(String.valueOf(size)).multiply(new BigDecimal(bl)).multiply(new BigDecimal("100"))
                            .divide(new BigDecimal("100"), RoundingMode.HALF_UP).intValue();
                }
                int endIndex = startIndex + rsCnt;
                if (endIndex > size) {
                    endIndex = size;
                }
                for (int i = startIndex; i < endIndex; i++) {
                    Map<String, String> map = mapList.get(i);
                    map.put("money", jcje);
                    map.put("djmc", djmc);
                    mapList.set(i, map);
                }
                startIndex = startIndex + rsCnt;
            }
            baseBean.writeLog("query uf_djfblj end.");
            baseBean.writeLog("distributeCount mapList C is:" + mapList);
            // 如果开启顺延，则需要找到扣款对象 sfkkdx 0-否  1-是
            if (StringUtils.equals(sfsy, "0")) {
                for (int i = mapList.size() - 1; i >= 0; i--) {
                    Map<String, String> map = mapList.get(i);
                    if (StringUtils.equals("0", map.get("isProtect"))) {
                        map.put("sfkkdx", "1");
                        mapList.set(i, map);
                        break;
                    }
                }
            }
            baseBean.writeLog("distributeCount mapList D is:" + mapList);

            // 绩效等级分布建模id
            String modeId = rs.getPropValue("qz_jx_zm_prop", "jx_dj_distribution_mode_id");
            // 绩效等级分布查询id
            String cusId = rs.getPropValue("qz_jx_zm_prop", "jx_dj_distribution_cus_id");
            SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");

            Map<String, String> idMap = new HashMap<>();
            Map<String, String> fbMap = new HashMap<>();
            Map<String, String> bmMap = new HashMap<>();
            Map<String, String> gwMap = new HashMap<>();
            rs.execute("SELECT a.id, a.subcompanyid1, a.departmentid, b." + gwFieldId + ", a.workcode " +
                    " FROM hrmresource a " +
                    " LEFT JOIN cus_fielddata b ON b.id = a.id AND b.scope = 'HrmCustomFieldByInfoType' AND b.scopeid = 3 ");
            while (rs.next()) {
                String id = rs.getString("id");
                String workcode = rs.getString("workcode");
                String subcompanyid1 = rs.getString("subcompanyid1");
                String departmentid = rs.getString("departmentid");
                String szgw = rs.getString(gwFieldId);
                if (StringUtils.isEmpty(id) || StringUtils.isEmpty(workcode) || StringUtils.isEmpty(subcompanyid1)
                        || StringUtils.isEmpty(departmentid) || StringUtils.isEmpty(szgw)) {
                    continue;
                }
                idMap.put(id, workcode);
                fbMap.put(id, subcompanyid1);
                bmMap.put(id, departmentid);
                gwMap.put(id, szgw);
            }

            // 保护期员工如果奖惩金额小于0，则取0
            List<List> insertParams = new ArrayList<>();
            for (int i = 0; i < mapList.size(); i++) {
                Map<String, String> map = mapList.get(i);
                String yg = map.get("yg");
                String df = map.get("df");
                if (StringUtils.isEmpty(df)) {
                    df = "0";
                }
                String jcje = map.get("money");
                if (StringUtils.isEmpty(jcje)) {
                    jcje = "0";
                }
                String sfbhq = map.get("isProtect");
                if (StringUtils.isEmpty(sfbhq)) {
                    sfbhq = "0";
                }
                if (StringUtils.equals(sfbhq, "1") && new BigDecimal(jcje).compareTo(BigDecimal.ZERO) < 0) {
                    jcje = "0";
                }
                String sfkkdx = map.get("sfkkdx");
                if (StringUtils.isEmpty(sfkkdx)) {
                    sfkkdx = "0";
                }
                String yggh = idMap.get(yg);
                String szfb = fbMap.get(yg);
                String szbm = bmMap.get(yg);
                String szgw = gwMap.get(yg);
                List insertParam = new ArrayList();
                insertParam.add(yg);
                insertParam.add(szny);
                insertParam.add(khjh);
                insertParam.add(map.get("djmc"));
                insertParam.add(df);
                insertParam.add(qzfbfa);
                insertParam.add(jcje);
                insertParam.add(sfbhq);
                insertParam.add(sfkkdx);
                insertParam.add(map.get("khfa"));
                insertParam.add(szfb);
                insertParam.add(szbm);
                insertParam.add(szgw);
                insertParam.add(yggh);
                insertParam.add(modeId);
                insertParam.add(cusId);
                insertParam.add("1");
                insertParam.add("0");
                insertParam.add(sdfDate.format(new Date()));
                insertParam.add(sdfTime.format(new Date()));
                insertParams.add(insertParam);
            }

            if (CollectionUtils.isEmpty(insertParams)) {
                baseBean.writeLog("distributeCount insertParams is null.");
            } else {
                baseBean.writeLog("distributeCount insertParams size:" + insertParams.size());
                String insertSql = "INSERT INTO uf_ygdjfbjl (yg,ny,khjh,dj,df,qzfbfa,jcje,sfbhq,sfkkdx,khfa,szfb,szbm,szgw,yggh,formmodeid," +
                        "MODEUUID, modedatacreater,modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                rs.executeBatchSql(insertSql, insertParams);
            }
        } catch (Exception e) {
            baseBean.writeLog("distributeCount error:" + e);
            result.put("mes", "系统错误，请联系管理员！");
            result.put("code", "400");
            return result;
        }
        baseBean.writeLog("distributeCount end.");
        result.put("mes", "正在计算，请稍等！");
        result.put("code", "200");
        return result;
    }

    @Override
    public Map<String, Object> rankCount(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        baseBean.writeLog("rankCount start:" + params);
        try {
            // 考核计划
            String khjh = Util.null2String(params.get("khjh"));
            if (StringUtils.isEmpty(khjh)) {
                baseBean.writeLog("rankCount khjh is null.");
                result.put("mes", "请选择考核计划！");
                result.put("code", "200");
                return result;
            }
            // 绩效排名方案
            String jxpmfa = Util.null2String(params.get("jxpmfa"));
            if (StringUtils.isEmpty(jxpmfa)) {
                baseBean.writeLog("rankCount jxpmfa is null.");
                result.put("mes", "请选择排名方案！");
                result.put("code", "200");
                return result;
            }
            RecordSet rs = new RecordSet();
            RecordSet rs1 = new RecordSet();
            // 获取考核计划所属年月
            String szny = null;
            rs.execute("select szny from uf_khjhdy where id = " + khjh);
            if (rs.next()) {
                szny = rs.getString("szny");
            }
            if (StringUtils.isEmpty(szny)) {
                baseBean.writeLog("distributeCount szny is null.");
                result.put("mes", "考核计划所属周期获取失败，请检查！");
                result.put("code", "200");
                return result;
            }

            // 岗位fieldId 3
            String gwFieldId = rs.getPropValue("qz_jx_zm_prop", "gw_field_id");
            // 职级fieldId 3
            String zjFieldId = rs.getPropValue("qz_jx_zm_prop", "zj_field_id");

            Set<String> rySet = new HashSet<>();
            rs.execute("SELECT * FROM uf_jxpmfa WHERE id = " + jxpmfa);
            while (rs.next()) {
                String gw = rs.getString("gw");
                String fs = rs.getString("fs");
                String fslb = rs.getString("fslb");
                String gdry = rs.getString("gdry");
                String zwxl = rs.getString("zwxl");
                String zj = rs.getString("zj");
                String sfbhq = rs.getString("sfbhq");

                if (StringUtils.isNotEmpty(gw)) {
                    String querySqlA = "SELECT a.id from hrmresource a, cus_fielddata b where a.id = b.id " +
                            " and b." + gwFieldId + " in (" + gw + ") and b.scope = 'HrmCustomFieldByInfoType' and scopeid = 3 " +
                            " AND a.status in (0,1,2,3) ";
                    rs1.execute(querySqlA);
                    while (rs1.next()) {
                        String idT = rs1.getString("id");
                        if (StringUtils.isNotEmpty(idT)) {
                            rySet.add(idT);
                        }
                    }
                }
                if (StringUtils.isNotEmpty(fs)) {
                    String querySqlA = "SELECT id from hrmresource where status in (0,1,2,3) AND subcompanyid1 in (" + fs + ")";
                    rs1.execute(querySqlA);
                    while (rs1.next()) {
                        String idT = rs1.getString("id");
                        if (StringUtils.isNotEmpty(idT)) {
                            rySet.add(idT);
                        }
                    }
                }
                if (StringUtils.isNotEmpty(fslb)) {
                    String querySqlA = "SELECT id from hrmresource where status in (0,1,2,3) AND subcompanyid1 in " +
                            " (SELECT fb from uf_yjtl WHERE lb in (" + fslb + "))";
                    rs1.execute(querySqlA);
                    while (rs1.next()) {
                        String idT = rs1.getString("id");
                        if (StringUtils.isNotEmpty(idT)) {
                            rySet.add(idT);
                        }
                    }
                }
                if (StringUtils.isNotEmpty(gdry)) {
                    rySet.addAll(Arrays.asList(gdry.split(",")));
                }
                if (StringUtils.isNotEmpty(zwxl)) {

                }
                if (StringUtils.isNotEmpty(zj)) {
                    String querySqlA = "SELECT a.id FROM hrmresource a, cus_fielddata b where a.id = b.id and " +
                            "b.scope = 'HrmCustomFieldByInfoType' and scopeid = 3 AND a.status in (0,1,2,3) and b."
                            + zjFieldId + " in (" + zj + ")";
                    rs1.execute(querySqlA);
                    while (rs1.next()) {
                        String idT = rs1.getString("id");
                        if (StringUtils.isEmpty(idT)) {
                            continue;
                        }
                        rySet.add(idT);
                    }
                }
            }
        } catch (Exception e) {
            baseBean.writeLog("rankCount error:" + e);
            result.put("mes", "系统错误，请联系管理员！");
            result.put("code", "400");
            return result;
        }
        baseBean.writeLog("rankCount end.");
        result.put("mes", "正在计算，请稍等！");
        result.put("code", "200");
        return result;
    }

    @Override
    public Map<String, Object> jxxsRankCount(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        baseBean.writeLog("jxxsRankCount start:" + params);
        try {
            // 考核计划
            String khjh = Util.null2String(params.get("khjh"));
            if (StringUtils.isEmpty(khjh)) {
                baseBean.writeLog("jxxsRankCount khjh is null.");
                result.put("mes", "请选择考核计划！");
                result.put("code", "200");
                return result;
            }
            // 绩效系数计算方案
            String jxxsjsfa = Util.null2String(params.get("jxxsjsfa"));
            if (StringUtils.isEmpty(jxxsjsfa)) {
                baseBean.writeLog("jxxsRankCount jxxsjsfa is null.");
                result.put("mes", "请选择绩效系数计算方案！");
                result.put("code", "200");
                return result;
            }

            RecordSet rs = new RecordSet();
            RecordSet rs1 = new RecordSet();

            // 获取考核计划所属年月
            String szny = null;
            rs.execute("select szny from uf_khjhdy where id = " + khjh);
            if (rs.next()) {
                szny = rs.getString("szny");
            }
            if (StringUtils.isEmpty(szny)) {
                baseBean.writeLog("jxxsRankCount szny is null.");
                result.put("mes", "考核计划所属周期获取失败，请检查！");
                result.put("code", "200");
                return result;
            }
            // 首先删除考核计划和强制分布方案对应的数据
            rs.execute("DELETE FROM uf_jxpmyxsjhjg WHERE khjh = " + khjh + " AND szjxxsjsfa = " + jxxsjsfa);

            // 定义一个DateTimeFormatter对象，用于解析年月字符串
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
            // 将字符串解析为YearMonth对象
            YearMonth yearMonth = YearMonth.parse(szny, formatter);
            // 从YearMonth对象中提取年份与月份
            int year = yearMonth.getYear();
            int month = yearMonth.getMonthValue();

            // 获取保护期人员
            Set<String> protectSet = new HashSet<>();
            rs.executeQuery("SELECT ygxm FROM uf_khbhqxxrg WHERE lx = 1 AND ((YEAR(CONVERT(date, ksrq)) = ? AND MONTH(CONVERT(date, ksrq)) = ?)" +
                    " OR (YEAR(CONVERT(date, jsrq)) = ? AND MONTH(CONVERT(date, jsrq)) = ?))", year, month, year, month);
            while (rs.next()) {
                String ygxm = rs.getString("ygxm");
                if (StringUtils.isNotEmpty(ygxm)) {
                    protectSet.add(ygxm);
                }
            }

            String ryfw = null;
            rs.execute("(SELECT ryflfa FROM uf_jxxsjsfa WHERE id = " + jxxsjsfa + ")");
            if (rs.next()) {
                ryfw = rs.getString("ryflfa");
            }
            if (StringUtils.isEmpty(ryfw)) {
                baseBean.writeLog("jxxsRankCount ryfw is null.");
                result.put("mes", "请设置强制分布方案中的人员范围！");
                result.put("code", "200");
                return result;
            }
            // 岗位fieldId 3
            String gwFieldId = rs.getPropValue("qz_jx_zm_prop", "gw_field_id");
            // 职级fieldId 3
            String zjFieldId = rs.getPropValue("qz_jx_zm_prop", "zj_field_id");

            // 获取分布方案人员范围
            Set<String> ryfwSet = new HashSet<>();
            rs.execute("select * from uf_jxpmfa where id =  " + ryfw);
            if (rs.next()) {
                String gw = rs.getString("gw");
                String fs = rs.getString("fs");
                String fslb = rs.getString("fslb");
                String gdry = rs.getString("gdry");
                String zwxl = rs.getString("zwxl");
                String zj = rs.getString("zj");
                String sfbhq = rs.getString("sfbhq");

                String sqlA = "SELECT a.id, b." + gwFieldId + " as gw, a.subcompanyid1, b." + zjFieldId + " as zj from hrmresource a " +
                        " LEFT JOIN cus_fielddata b ON a.id = b.id and b.scope = 'HrmCustomFieldByInfoType' and scopeid = 3 " +
                        " WHERE a.status in (0,1,2,3) ";
                if (StringUtils.isNotEmpty(fs)) {
                    sqlA = sqlA + " AND a.subcompanyid1 in (" + fs + ") ";
                }
                if (StringUtils.isNotEmpty(gdry)) {
                    sqlA = sqlA + " AND a.id in (" + gdry + ") ";
                }
                if (StringUtils.isNotEmpty(fslb)) {
                    sqlA = sqlA + " AND a.subcompanyid1 in (SELECT fb from uf_yjtl WHERE lb in (" + fslb + ")) ";
                }
                Set<String> gwSet = new HashSet<>();
                if (StringUtils.isNotEmpty(zwxl)) {
                    String xl = "P";
                    if (StringUtils.equals(zwxl, "1")) {
                        xl = "M";
                    }
                    rs1.executeQuery("select id from uf_JCL_GWGL where szzwxl in (select id from uf_zwxl where xlbm = ?)", xl);
                    while (rs1.next()) {
                        String idT = rs1.getString("id");
                        if (StringUtils.isEmpty(idT)) {
                            continue;
                        }
                        gwSet.add(idT);
                    }
                }

                Set<String> gwSetNew = new HashSet<>();
                if (StringUtils.isNotEmpty(gw)) {
                    String[] gwmcArr = gw.split("；");
                    String gwmcSql = "SELECT id FROM uf_JCL_GWGL ";
                    for (int i = 0; i < gwmcArr.length; i++) {
                        if (i == 0) {
                            gwmcSql = gwmcSql + " WHERE gwmc LIKE '%" + gwmcArr[i] + "%' ";
                        } else {
                            gwmcSql = gwmcSql + " OR gwmc LIKE '%" + gwmcArr[i] + "%' ";
                        }
                    }

                    rs1.execute(gwmcSql);
                    while (rs1.next()) {
                        String id = rs1.getString("id");
                        if (StringUtils.isNotEmpty(id));
                        gwSetNew.add(id);
                    }
                }

                baseBean.writeLog("jxxsRankCount sqlA:" + sqlA);
                rs1.execute(sqlA);
                while (rs1.next()) {
                    String id = rs1.getString("id");
                    String gwT = rs1.getString("gw");
                    String zjT = rs1.getString("zj");
                    if (StringUtils.isNotEmpty(gw)) {
                        if (CollectionUtils.isEmpty(gwSetNew) || !gwSetNew.contains(gwT)) {
                            continue;
                        }
                    }
                    if (StringUtils.isNotEmpty(zwxl)) {
                        if (CollectionUtils.isEmpty(gwSet) || !gwSet.contains(gwT)) {
                            continue;
                        }
                    }
                    if (StringUtils.isNotEmpty(zj)) {
                        List<String> list = Arrays.asList(zj.split(","));
                        if (!list.contains(zjT)) {
                            continue;
                        }
                    }
                    if (StringUtils.equals(sfbhq, "0")) {
                        if (CollectionUtils.isEmpty(protectSet) || !protectSet.contains(id)) {
                            continue;
                        }
                    }
                    if (StringUtils.equals(sfbhq, "1")) {
                        if ((!CollectionUtils.isEmpty(protectSet)) && protectSet.contains(id)) {
                            continue;
                        }
                    }
                    ryfwSet.add(id);
                }
            }

            if (CollectionUtils.isEmpty(ryfwSet)) {
                baseBean.writeLog("jxxsRankCount ryfwSet is null.");
                result.put("mes", "人员范围获取失败！");
                result.put("code", "200");
                return result;
            }

            String querySqlDf = "SELECT * FROM uf_jxdfjgb WHERE khjh = ? AND df is not null ORDER BY df DESC";
            Map<String, Map<String, String>> mapMap = new HashMap<>();
            String oldDf = "-1";
            Map<String, String> idMap = new HashMap<>();
            int idCnt = 0;
            int idAll = 0;
            rs.executeQuery(querySqlDf, khjh);
            while (rs.next()) {
                String id = rs.getString("id");
                String yg = rs.getString("yg");
                if (!ryfwSet.contains(yg)) {
                    continue;
                }
                String df = rs.getString("df");
                if (StringUtils.isEmpty(df)) {
                    df = "0";
                }
                if (new BigDecimal(oldDf).compareTo(new BigDecimal(df)) == 0) {

                } else {
                    idCnt = idCnt + 1;
                }
                oldDf = df;

                Map<String, String> mapTemp = new HashMap<>();
                mapTemp.put("yg", yg);
                mapTemp.put("rank", String.valueOf(idCnt));
                mapTemp.put("df", df);
                mapMap.put(id, mapTemp);
                String value = idCnt + "_" + df;
                idMap.put(id, value);
                idAll = idAll + 1;
            }

            if (CollectionUtils.isEmpty(idMap)) {
                baseBean.writeLog("jxxsRankCount idMap is null.");
                result.put("mes", "无人员需要计算！");
                result.put("code", "200");
                return result;
            }
            baseBean.writeLog("jxxsRankCount idMap is:" + JSONObject.toJSONString(idMap));
            List<Map<String, String>> needInsertMap = new ArrayList<>();
            Set<String> insertSet = new HashSet<>();
            rs.executeQuery("SELECT * FROM uf_jxxsjsfa_dt1 WHERE mainid = ? ORDER BY jssx", jxxsjsfa);
            while (rs.next()) {
                String dyjxxs = rs.getString("dyjxxs");
                String pmmcks = rs.getString("pmmcks");
                String pmmcjs = rs.getString("pmmcjs");
                String pmqjks = rs.getString("pmqjks");
                String pmqjjs = rs.getString("pmqjjs");
                String dfyqksqj = rs.getString("dfyqksqj");
                String dfyqjsqj = rs.getString("dfyqjsqj");
                String qzlj = rs.getString("qzlj");
                boolean mcFilter = false;
                Map<String, String> idMapTemp = new HashMap<>();
                if (StringUtils.isNotEmpty(pmmcks) || StringUtils.isNotEmpty(pmmcjs)) {
                    mcFilter = true;
                    if (StringUtils.isEmpty(pmmcks)) {
                        pmmcks = "0";
                    }
                    if (new BigDecimal(pmmcks).compareTo(new BigDecimal("-1")) == 0) {
                        pmmcks = String.valueOf(idCnt);
                    }
                    if (StringUtils.isEmpty(pmmcjs)) {
                        for (Map.Entry<String, String> entry : idMap.entrySet()) {
                            String key = entry.getKey();
                            String pmValue = entry.getValue().split("_")[0];
                            if (StringUtils.isEmpty(pmValue)) {
                                pmValue = "0";
                            }
                            if (new BigDecimal(pmValue).compareTo(new BigDecimal(pmmcks)) >= 0) {
                                idMapTemp.put(key, entry.getValue());
                            }
                        }
                    } else {
                        if (new BigDecimal(pmmcjs).compareTo(new BigDecimal("-1")) == 0) {
                            pmmcjs = String.valueOf(idCnt);
                        }
                        for (Map.Entry<String, String> entry : idMap.entrySet()) {
                            String key = entry.getKey();
                            String pmValue = entry.getValue().split("_")[0];
                            if (StringUtils.isEmpty(pmValue)) {
                                pmValue = "0";
                            }
                            if (new BigDecimal(pmValue).compareTo(new BigDecimal(pmmcks)) >= 0 &&
                                    new BigDecimal(pmValue).compareTo(new BigDecimal(pmmcjs)) <= 0) {
                                idMapTemp.put(key, entry.getValue());
                            }
                        }
                    }
                }
                if (mcFilter && CollectionUtils.isEmpty(idMapTemp)) {
                    continue;
                }
                boolean qjFilter = false;
                if (StringUtils.isNotEmpty(pmqjks) || StringUtils.isNotEmpty(pmqjjs)) {
                    qjFilter = true;
                    if (StringUtils.isEmpty(pmqjks)) {
                        pmqjks = "0";
                    }
                    String startIndex = "0";
                    if (StringUtils.equals(qzlj, "0")) {
                        startIndex = new BigDecimal(String.valueOf(idAll)).multiply(new BigDecimal(pmqjks))
                                .setScale(0, RoundingMode.UP).toString();
                    } else if (StringUtils.equals(qzlj, "1")) {
                        startIndex = new BigDecimal(String.valueOf(idAll)).multiply(new BigDecimal(pmqjks))
                                .setScale(0, RoundingMode.DOWN).toString();
                    } else {
                        startIndex = new BigDecimal(String.valueOf(idAll)).multiply(new BigDecimal(pmqjks))
                                .setScale(0, RoundingMode.HALF_UP).toString();
                    }
                    Map<String, String> idMapTempA = idMap;
                    if (mcFilter) {
                        idMapTempA = idMapTemp;
                    }
                    idMapTemp = new HashMap<>();
                    if (StringUtils.isEmpty(pmqjjs)) {
                        for (Map.Entry<String, String> entry : idMapTempA.entrySet()) {
                            String key = entry.getKey();
                            String pmValue = entry.getValue().split("_")[0];
                            if (StringUtils.isEmpty(pmValue)) {
                                pmValue = "0";
                            }
                            if (new BigDecimal(pmValue).compareTo(new BigDecimal(startIndex)) >= 0) {
                                idMapTemp.put(key, entry.getValue());
                            }
                        }
                    } else {
                        String endIndex = "0";
                        if (StringUtils.equals(qzlj, "0")) {
                            endIndex = new BigDecimal(String.valueOf(idAll)).multiply(new BigDecimal(pmqjjs))
                                    .setScale(0, RoundingMode.UP).toString();
                        } else if (StringUtils.equals(qzlj, "1")) {
                            endIndex = new BigDecimal(String.valueOf(idAll)).multiply(new BigDecimal(pmqjjs))
                                    .setScale(0, RoundingMode.DOWN).toString();
                        } else {
                            endIndex = new BigDecimal(String.valueOf(idAll)).multiply(new BigDecimal(pmqjjs))
                                    .setScale(0, RoundingMode.HALF_UP).toString();
                        }
                        for (Map.Entry<String, String> entry : idMapTempA.entrySet()) {
                            String key = entry.getKey();
                            String pmValue = entry.getValue().split("_")[0];
                            if (StringUtils.isEmpty(pmValue)) {
                                pmValue = "0";
                            }
                            if (new BigDecimal(pmValue).compareTo(new BigDecimal(startIndex)) >= 0 &&
                                    new BigDecimal(pmValue).compareTo(new BigDecimal(endIndex)) <= 0) {
                                idMapTemp.put(key, entry.getValue());
                            }
                        }
                    }
                }

                if ((mcFilter || qjFilter) && CollectionUtils.isEmpty(idMapTemp)) {
                    continue;
                }
                if (StringUtils.isNotEmpty(dfyqksqj) || StringUtils.isNotEmpty(dfyqjsqj)) {
                    if (StringUtils.isEmpty(dfyqksqj)) {
                        dfyqksqj = "0";
                    }
                    Map<String, String> idMapTempA = idMap;
                    if (mcFilter || qjFilter) {
                        idMapTempA = idMapTemp;
                    }
                    idMapTemp = new HashMap<>();
                    if (StringUtils.isEmpty(dfyqjsqj)) {
                        for (Map.Entry<String, String> entry : idMapTempA.entrySet()) {
                            String key = entry.getKey();
                            String dfValue = entry.getValue().split("_")[1];
                            if (StringUtils.isEmpty(dfValue)) {
                                dfValue = "0";
                            }
                            if (new BigDecimal(dfValue).compareTo(new BigDecimal(dfyqksqj)) >= 0) {
                                idMapTemp.put(key, entry.getValue());
                            }
                        }
                    } else {
                        for (Map.Entry<String, String> entry : idMapTempA.entrySet()) {
                            String key = entry.getKey();
                            String dfValue = entry.getValue().split("_")[1];
                            if (StringUtils.isEmpty(dfValue)) {
                                dfValue = "0";
                            }
                            if (new BigDecimal(dfValue).compareTo(new BigDecimal(dfyqksqj)) >= 0 &&
                                    new BigDecimal(dfValue).compareTo(new BigDecimal(dfyqjsqj)) <= 0) {
                                idMapTemp.put(key, entry.getValue());
                            }
                        }
                    }
                }

                if (!CollectionUtils.isEmpty(idMapTemp)) {
                    for (Map.Entry<String, String> entry : idMapTemp.entrySet()) {
                        String key = entry.getKey();
                        if ((!CollectionUtils.isEmpty(insertSet)) && insertSet.contains(key)) {
                            continue;
                        }
                        Map<String, String> map = mapMap.get(key);
                        map.put("dyjxxs", dyjxxs);
                        needInsertMap.add(map);
                        insertSet.add(key);
                    }
                }
            }

            for (Map.Entry<String, String> entry : idMap.entrySet()) {
                String key = entry.getKey();
                if ((!CollectionUtils.isEmpty(insertSet)) && insertSet.contains(key)) {
                    continue;
                } else {
                    Map<String, String> map = mapMap.get(key);
                    map.put("dyjxxs", "0");
                    needInsertMap.add(map);
                    insertSet.add(key);
                }
            }

            if (CollectionUtils.isEmpty(needInsertMap)) {
                baseBean.writeLog("jxxsRankCount needInsertMap is null.");
            } else {
                baseBean.writeLog("jxxsRankCount needInsertMap is:" + JSONObject.toJSONString(needInsertMap));
                List<List> insertList = new ArrayList<>();
                SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
                SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
                // 绩效排名与系数结合结果建模id
                String modeId = rs.getPropValue("qz_jx_zm_prop", "jxpmyxsjh_mode_id");
                // 绩效排名与系数结合结果查询id
                String cusId = rs.getPropValue("qz_jx_zm_prop", "jxpmyxsjh_cus_id");

                Map<String, String> idAndGhMap = new HashMap<>();
                Map<String, String> fbMap = new HashMap<>();
                Map<String, String> bmMap = new HashMap<>();
                Map<String, String> gwMap = new HashMap<>();
                rs.execute("SELECT a.id, a.subcompanyid1, a.departmentid, b." + gwFieldId + ", a.workcode " +
                        " FROM hrmresource a " +
                        " LEFT JOIN cus_fielddata b ON b.id = a.id AND b.scope = 'HrmCustomFieldByInfoType' AND b.scopeid = 3 ");
                while (rs.next()) {
                    String id = rs.getString("id");
                    String workcode = rs.getString("workcode");
                    String subcompanyid1 = rs.getString("subcompanyid1");
                    String departmentid = rs.getString("departmentid");
                    String szgw = rs.getString(gwFieldId);
                    if (StringUtils.isEmpty(id) || StringUtils.isEmpty(workcode) || StringUtils.isEmpty(subcompanyid1)
                            || StringUtils.isEmpty(departmentid) || StringUtils.isEmpty(szgw)) {
                        continue;
                    }
                    idAndGhMap.put(id, workcode);
                    fbMap.put(id, subcompanyid1);
                    bmMap.put(id, departmentid);
                    gwMap.put(id, szgw);
                }

                for (Map<String, String> insertMap : needInsertMap) {
                    String yg = insertMap.get("yg");
                    String df = insertMap.get("df");
                    if (StringUtils.isEmpty(df)) {
                        df = "0";
                    }
                    String pm = insertMap.get("rank");
                    if (StringUtils.isEmpty(pm)) {
                        pm = "0";
                    }
                    String jxxs = insertMap.get("dyjxxs");
                    if (StringUtils.isEmpty(jxxs)) {
                        jxxs = "0";
                    }

                    String yggh = idAndGhMap.get(yg);
                    String szfb = fbMap.get(yg);
                    String szbm = bmMap.get(yg);
                    String szgw = gwMap.get(yg);
                    List<String> arrayList = new ArrayList<>();
                    arrayList.add(khjh);
                    arrayList.add(jxxsjsfa);
                    arrayList.add(jxxs);
                    arrayList.add(yg);
                    arrayList.add(pm);
                    arrayList.add(df);
                    arrayList.add(szfb);
                    arrayList.add(szbm);
                    arrayList.add(szgw);
                    arrayList.add(yggh);
                    arrayList.add(modeId);
                    arrayList.add(cusId);
                    arrayList.add("1");
                    arrayList.add("0");
                    arrayList.add(sdfDate.format(new Date()));
                    arrayList.add(sdfTime.format(new Date()));
                    insertList.add(arrayList);
                }

                if (CollectionUtils.isEmpty(insertList)) {
                    baseBean.writeLog("jxxsRankCount insertList is null.");
                } else {
                    baseBean.writeLog("jxxsRankCount insertList size is:" + insertList.size());
                    String insertSql = "INSERT INTO uf_jxpmyxsjhjg (khjh, szjxxsjsfa, jxxs, yg, pm, zzdf, szfb, szbm, szgw, yggh," +
                            "formmodeid,MODEUUID, modedatacreater,modedatacreatertype, modedatacreatedate, modedatacreatetime) " +
                            "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                    rs.executeBatchSql(insertSql, insertList);
                }

                // 权限重构
                ModeRightInfo modeRightInfo = new ModeRightInfo();
                modeRightInfo.setNewRight(true);
                modeRightInfo.editModeDataShare(1, Integer.parseInt(modeId), Integer.parseInt(cusId));
            }
        } catch (Exception e) {
            baseBean.writeLog("jxxsRankCount error:" + e);
            result.put("mes", "系统错误，请联系管理员！");
            result.put("code", "400");
            return result;
        }
        baseBean.writeLog("jxxsRankCount end.");
        result.put("mes", "正在计算，请稍等！");
        result.put("code", "200");
        return result;
    }

    @Override
    public Map<String, Object> jdUpgradeCount(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        baseBean.writeLog("jdUpgradeCount start:" + params);
        try {
            String today = DateUtil.format(new Date(), "yyyy-MM-dd");
            // 年份
            String nf = Util.null2String(params.get("nf"));
            if (StringUtils.isEmpty(nf)) {
                nf = today.substring(0, 4);
            }

            List<String> firstQuarter = Arrays.asList("01", "02", "03");
            List<String> secondQuarter = Arrays.asList("04", "05", "06");
            List<String> thirdQuarter = Arrays.asList("07", "08", "09");
            List<String> fourthQuarter = Arrays.asList("10", "11", "12");

            List<String> nyList = new ArrayList<>();
            // 季度
            String jd = Util.null2String(params.get("jd"));
            if (StringUtils.isEmpty(jd)) {
                String yf = today.substring(5, 7);
                List<String> nyTempList = new ArrayList<>();
                if (firstQuarter.contains(yf)) {
                    nyTempList = firstQuarter;
                } else if (secondQuarter.contains(yf)) {
                    nyTempList = secondQuarter;
                } else if (thirdQuarter.contains(yf)) {
                    nyTempList = thirdQuarter;
                } else {
                    nyTempList = fourthQuarter;
                }

                for (String yfTemp : nyTempList) {
                    nyList.add(nf + "-" + yfTemp);
                }
            } else {
                List<String> nyTempList = new ArrayList<>();
                if (StringUtils.equals(jd, "1")) {
                    nyTempList = firstQuarter;
                } else if (StringUtils.equals(jd, "2")) {
                    nyTempList = secondQuarter;
                } else if (StringUtils.equals(jd, "3")) {
                    nyTempList = thirdQuarter;
                } else {
                    nyTempList = fourthQuarter;
                }

                for (String yfTemp : nyTempList) {
                    nyList.add(nf + "-" + yfTemp);
                }
            }

            if (CollectionUtils.isEmpty(nyList)) {
                baseBean.writeLog("jdUpgradeCount nyList is null.");
                result.put("mes", "系统错误，请联系管理员！");
                result.put("code", "200");
                return result;
            }
            // 季度升级考核方案
            String jdsjkhfa = Util.null2String(params.get("jdsjkhfa"));
            if (StringUtils.isEmpty(jdsjkhfa)) {
                baseBean.writeLog("jdUpgradeCount jdsjkhfa is null.");
                result.put("mes", "请选择季度升级考核方案！");
                result.put("code", "200");
                return result;
            }

            RecordSet rs = new RecordSet();

            // 先删除相关数据
            rs.executeUpdate("DELETE FROM uf_jdsjjgb WHERE szjdsjkhfa = ? AND szjd = ? AND sznf = ?", jdsjkhfa, jd, nf);

            RecordSet rs1 = new RecordSet();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            int month1 = LocalDate.parse(nyList.get(0) + "-01", formatter).getMonthValue();
            int month2 = LocalDate.parse(nyList.get(1) + "-01", formatter).getMonthValue();
            int month3 = LocalDate.parse(nyList.get(2) + "-01", formatter).getMonthValue();
            // 获取保护期人员
            Set<String> protectSet = new HashSet<>();
            rs.executeQuery("SELECT ygxm FROM uf_khbhqxxrg WHERE lx = 1 AND ((YEAR(CONVERT(date, ksrq)) = ? AND MONTH(CONVERT(date, ksrq)) = ?)" +
                            " OR (YEAR(CONVERT(date, jsrq)) = ? AND MONTH(CONVERT(date, jsrq)) = ?)  OR (YEAR(CONVERT(date, jsrq)) = ? AND MONTH(CONVERT(date, jsrq)) = ?))"
                    , nf, month1, nf, month2, nf, month3);
            while (rs.next()) {
                String ygxm = rs.getString("ygxm");
                if (StringUtils.isNotEmpty(ygxm)) {
                    protectSet.add(ygxm);
                }
            }

            String[] str = nyList.get(2).split("-");
            YearMonth yearMonth1 =
                    YearMonth.of(Integer.parseInt(str[0]), Integer.parseInt(str[1]));
            // 使用LocalDate类获取所选季度的最后一天
            LocalDate currentDate = yearMonth1.atEndOfMonth();
            int lastDay = yearMonth1.lengthOfMonth();

            // 获取当前季度首月相关信息
            String[] strFirst = nyList.get(0).split("-");
            YearMonth yearMonthFirst =
                    YearMonth.of(Integer.parseInt(strFirst[0]), Integer.parseInt(strFirst[1]));
            int lastDayFirst = yearMonthFirst.lengthOfMonth();

            String jhksrq = nyList.get(0) + "-01";

            // 获取人员负责部门数量
            rs.execute("SELECT id,bmfzr FROM hrmdepartment where bmfzr is not null");
            Map<String, Integer> bmCntMap = new HashMap<>();
            while (rs.next()) {
                String bmId = rs.getString("id");
                String bmfzr = rs.getString("bmfzr");
                if (StringUtils.isEmpty(bmfzr)) {
                    continue;
                }
                String[] bmfzrArr = bmfzr.split(",");
                for (String r : bmfzrArr) {
                    if ((!CollectionUtils.isEmpty(bmCntMap)) && bmCntMap.containsKey(r)) {
                        Integer integer = bmCntMap.get(r);
                        bmCntMap.put(r, integer + 1);
                    } else {
                        bmCntMap.put(r, 1);
                    }
                }
            }


            // 获取所有调动人员对应最新日期
            Map<String, String> ddrqMap = new HashMap<>();
            rs.execute("SELECT yg, Max(shenxrq) AS ddrq FROM uf_rzjl where bdsj = 2 GROUP BY yg");
            while (rs.next()) {
                String yg = rs.getString("yg");
                String ddrq = rs.getString("ddrq");
                if (StringUtils.isEmpty(yg) || StringUtils.isEmpty(ddrq)) {
                    continue;
                }
                ddrqMap.put(yg, ddrq);
            }

            // 岗位fieldId 3
            String gwFieldId = rs.getPropValue("qz_jx_zm_prop", "gw_field_id");
            // 职级fieldId 3
            String zjFieldId = rs.getPropValue("qz_jx_zm_prop", "zj_field_id");

            // 人员统计范围逻辑
            String rytjfwlj = null;
            // 排名统计逻辑
            String pmtjlj = null;
            // 排名额外筛选条件
            String pmewsxtj = null;
            // 升级范围
            String sjfw = null;
            // 范围取整逻辑
            String fwqzlj = null;
            // 职级变动类别
            String zjbdlb = null;
            // 薪酬调整金额
            String xcdzje = null;

            Map<String, Map<String, String>> rysxMap = new HashMap<>();
            rs.execute("SELECT * FROM uf_rysxtj");
            while (rs.next()) {
                String id = rs.getString("id");
                String szfbbhxj = rs.getString("szfbbhxj");
                String ygzt = rs.getString("ygzt");
                String gw = rs.getString("gw");
                String bm = rs.getString("bm");
                String jtry = rs.getString("jtry");
                String gwxl = rs.getString("gwxl");
                String sfbmtdfzr = rs.getString("sfbmtdfzr");
                String rylb = rs.getString("rylb");
                String zj = rs.getString("zj");
                String rzkssj = rs.getString("rzkssj");
                String rzjssj = rs.getString("rzjssj");
                String gwbdsxkssj = rs.getString("gwbdsxkssj");
                String gwbdsxsjjs = rs.getString("gwbdsxsjjs");
                String lzkssj = rs.getString("lzkssj");
                String lzjssj = rs.getString("lzjssj");
                String rzts = rs.getString("rzts");
                String zxgwbdsxts = rs.getString("zxgwbdsxts");
                String sfbhq = rs.getString("sfbhq");
                String xxbmtd = rs.getString("xxbmtd");
                String ryzxmc = rs.getString("ryzxmc");
                String gwmc = rs.getString("gwmc");
                String zjx = rs.getString("zjx");

                Map<String, String> rysxMapTemp = new HashMap<>();
                rysxMapTemp.put("szfbbhxj", szfbbhxj);
                rysxMapTemp.put("ygzt", ygzt);
                rysxMapTemp.put("gw", gw);
                rysxMapTemp.put("bm", bm);
                rysxMapTemp.put("jtry", jtry);
                rysxMapTemp.put("gwxl", gwxl);
                rysxMapTemp.put("sfbmtdfzr", sfbmtdfzr);
                rysxMapTemp.put("rylb", rylb);
                rysxMapTemp.put("zj", zj);
                rysxMapTemp.put("rzkssj", rzkssj);
                rysxMapTemp.put("rzjssj", rzjssj);
                rysxMapTemp.put("gwbdsxkssj", gwbdsxkssj);
                rysxMapTemp.put("gwbdsxsjjs", gwbdsxsjjs);
                rysxMapTemp.put("lzkssj", lzkssj);
                rysxMapTemp.put("lzjssj", lzjssj);
                rysxMapTemp.put("rzts", rzts);
                rysxMapTemp.put("zxgwbdsxts", zxgwbdsxts);
                rysxMapTemp.put("sfbhq", sfbhq);
                rysxMapTemp.put("xxbmtd", xxbmtd);
                rysxMapTemp.put("ryzxmc", ryzxmc);
                rysxMapTemp.put("gwmc", gwmc);
                rysxMapTemp.put("zjx", zjx);

                rysxMap.put(id, rysxMapTemp);
            }

            Set<String> rySet = new HashSet<>();

            /*rs.execute("SELECT a.*, b.gw,b.gwmc,b.bm,b.jtry,b.gwxl,b.sfbmtdfzr,b.rylb,b.zj,b.rzkssj,b.rzjssj,b.gwbdsxkssj," +
                    "b.gwbdsxsjjs,b.lzkssj,b.lzjssj,b.rzts,b.zxgwbdsxts,b.sfbhq,b.xxbmtd,b.ygzt" +
                    " FROM uf_jdsjkhfab a LEFT JOIN uf_rysxtj b ON a.rytjfwlj = b.id WHERE a.id = " + jdsjkhfa);*/
            rs.execute("SELECT a.* FROM uf_jdsjkhfab WHERE id = " + jdsjkhfa);
            while (rs.next()) {
                rytjfwlj = rs.getString("rytjfwlj");
                pmtjlj = rs.getString("pmtjlj");
                pmewsxtj = rs.getString("pmewsxtj");
                sjfw = rs.getString("sjfw");
                fwqzlj = rs.getString("fwqzlj");
                zjbdlb = rs.getString("zjbdlb");
                xcdzje = rs.getString("xcdzje");

                if (StringUtils.isEmpty(rytjfwlj)) {
                    continue;
                }

                String[] khdxbdljidArr = rytjfwlj.split(",");
                for (String khdxbdljidTemp : khdxbdljidArr) {
                    Map<String, String> rysxTemp = rysxMap.get(khdxbdljidTemp);
                    if (CollectionUtils.isEmpty(rysxTemp)) {
                        continue;
                    }
                    String sqlA = "SELECT a.id,b." + gwFieldId + " as gw, a.subcompanyid1, b." + zjFieldId + " as zj FROM hrmresource a " +
                            " LEFT JOIN cus_fielddata b ON a.id = b.id and b.scope = 'HrmCustomFieldByInfoType' and scopeid = 3 " +
                            " WHERE 1 = 1 ";

                    String ygzt = rysxTemp.get("ygzt");
                    if (StringUtils.isNotEmpty(ygzt)) {
                        sqlA = sqlA + " and a.status in (" + ygzt + ") ";
                    }
                    String bm = rysxTemp.get("bm");
                    if (StringUtils.isNotEmpty(bm)) {
                        sqlA = sqlA + " and a.departmentid in (" + bm + ") ";
                    }
//                String jtry = rs.getString("jtry");
//                if (StringUtils.isNotEmpty(jtry)) {
//                    sqlA = sqlA + " and a.id in (" + jtry + ") ";
//                }
                    String sfbmtdfzr = rysxTemp.get("sfbmtdfzr");
                    Set<String> rySetA = new HashSet<>();
                    if (StringUtils.isNotEmpty(sfbmtdfzr) && StringUtils.equals(sfbmtdfzr, "0")) {
                        rs1.execute("SELECT bmfgld FROM hrmdepartment WHERE bmfgld is not null and (canceled is null or canceled != 1)");
                        while (rs1.next()) {
                            String bmfzrT = rs1.getString("bmfgld");
                            if (StringUtils.isEmpty(bmfzrT)) {
                                continue;
                            }
                            rySetA.addAll(Arrays.asList(bmfzrT.split(",")));
                        }
                        if (!CollectionUtils.isEmpty(rySetA)) {
                            sqlA = sqlA + " and a.id in (" + String.join(",", rySetA) + ") ";
                        }
                    }

                    String rylb = rysxTemp.get("rylb");
                    if (StringUtils.isNotEmpty(rylb)) {
                        sqlA = sqlA + " and a.usekind in (" + rylb + ") ";
                    }

                    String rzkssj = rysxTemp.get("rzkssj");
                    if (StringUtils.isNotEmpty(rzkssj) && ((new BigDecimal(rzkssj).compareTo(new BigDecimal("1")) >= 0
                            && new BigDecimal(rzkssj).compareTo(new BigDecimal(String.valueOf(lastDayFirst))) <= 0) || new BigDecimal(rzkssj).compareTo(new BigDecimal("99")) == 0)) {
                        String rzkssjT = "";
                        if (new BigDecimal(rzkssj).compareTo(new BigDecimal("99")) == 0) {
                            rzkssjT = yearMonthFirst.atDay(lastDayFirst).toString();
                        } else {
                            rzkssjT = yearMonthFirst.atDay(Integer.parseInt(rzkssj)).toString();
                        }
                        sqlA = sqlA + " and a.companystartdate >= '" + rzkssjT + "' ";
                    }
                    String rzjssj = rysxTemp.get("rzjssj");
                    if (StringUtils.isNotEmpty(rzjssj) && ((new BigDecimal(rzjssj).compareTo(new BigDecimal("1")) >= 0
                            && new BigDecimal(rzjssj).compareTo(new BigDecimal(String.valueOf(lastDay))) <= 0) || new BigDecimal(rzjssj).compareTo(new BigDecimal("99")) == 0)) {
                        String rzjssjT = "";
                        if (new BigDecimal(rzjssj).compareTo(new BigDecimal("99")) == 0) {
                            rzjssjT = yearMonth1.atDay(lastDay).toString();
                        } else {
                            rzjssjT = yearMonth1.atDay(Integer.parseInt(rzjssj)).toString();
                        }
                        sqlA = sqlA + " and a.companystartdate <= '" + rzjssjT + "' ";
                    }

                    String lzkssj = rysxTemp.get("lzkssj");
                    if (StringUtils.isNotEmpty(lzkssj) && ((new BigDecimal(lzkssj).compareTo(new BigDecimal("1")) >= 0
                            && new BigDecimal(lzkssj).compareTo(new BigDecimal(String.valueOf(lastDayFirst))) <= 0) || new BigDecimal(lzkssj).compareTo(new BigDecimal("99")) == 0)) {
                        String lzkssjT = "";
                        if (new BigDecimal(lzkssj).compareTo(new BigDecimal("99")) == 0) {
                            lzkssjT = yearMonthFirst.atDay(lastDayFirst).toString();
                        } else {
                            lzkssjT = yearMonthFirst.atDay(Integer.parseInt(lzkssj)).toString();
                        }
                        sqlA = sqlA + " and a.enddate >= '" + lzkssjT + "' ";
                    }
                    String lzjssj = rysxTemp.get("lzjssj");
                    if (StringUtils.isNotEmpty(lzjssj) && ((new BigDecimal(lzjssj).compareTo(new BigDecimal("1")) >= 0
                            && new BigDecimal(lzjssj).compareTo(new BigDecimal(String.valueOf(lastDay))) <= 0) || new BigDecimal(lzjssj).compareTo(new BigDecimal("99")) == 0)) {
                        String lzjssjT = "";
                        if (new BigDecimal(lzjssj).compareTo(new BigDecimal("99")) == 0) {
                            lzjssjT = yearMonth1.atDay(lastDay).toString();
                        } else {
                            lzjssjT = yearMonth1.atDay(Integer.parseInt(lzjssj)).toString();
                        }
                        sqlA = sqlA + " and a.enddate <= '" + lzjssjT + "' ";
                    }
                    String rzts = rysxTemp.get("rzts");
                    if (StringUtils.isNotEmpty(rzts) && !StringUtils.equals(rzts, "0")) {
                        LocalDate previousDate = currentDate.minusDays(Integer.parseInt(rzts));
                        sqlA = sqlA + " and a.companystartdate >= '" + previousDate + "' ";
                    }

                    String xxbmtd = rysxTemp.get("xxbmtd");
                    Set<String> rySetB = new HashSet<>();
                    if (StringUtils.isNotEmpty(xxbmtd) && (!StringUtils.equals(xxbmtd, "0")) && (!CollectionUtils.isEmpty(bmCntMap))) {
                        for (Map.Entry<String, Integer> entry : bmCntMap.entrySet()) {
                            String key = entry.getKey();
                            Integer value = entry.getValue();
                            if (value == Integer.parseInt(xxbmtd)) {
                                rySetB.add(key);
                            }
                        }
                        if (!CollectionUtils.isEmpty(rySetB)) {
                            sqlA = sqlA + " and a.id in (" + String.join(",", rySetB) + ") ";
                        }
                    }

                    String sfbhq = rysxTemp.get("sfbhq");
//                if (StringUtils.isNotEmpty(sfbhq) && StringUtils.equals(sfbhq, "0")) {
//                    rs1.execute("SELECT ygxm FROM uf_khbhqxxrg  where lx = 1");
//                    while (rs1.next()) {
//                        String idT = rs1.getString("ygxm");
//                        if (StringUtils.isEmpty(idT)) {
//                            continue;
//                        }
//                        rySet.add(idT);
//                    }
//                }

                    Set<String> gwSet = new HashSet<>();
                    String zwxl = rysxTemp.get("gwxl");
                    if (StringUtils.isNotEmpty(zwxl)) {
                        String xl = "P";
                        if (StringUtils.equals(zwxl, "1")) {
                            xl = "M";
                        }
                        rs1.executeQuery("select id from uf_JCL_GWGL where szzwxl in (select id from uf_zwxl where xlbm = ?)", xl);
                        while (rs1.next()) {
                            String idT = rs1.getString("id");
                            if (StringUtils.isEmpty(idT)) {
                                continue;
                            }
                            gwSet.add(idT);
                        }
                    }

                    String gwbdsxkssj = rysxTemp.get("gwbdsxkssj");
                    String gwbdsxsjjs = rysxTemp.get("gwbdsxsjjs");
                    String zxgwbdsxts = rysxTemp.get("zxgwbdsxts");

                    String gw = rysxTemp.get("gw");
                    String gwmc = rysxTemp.get("gwmc");
                    Set<String> gwmcSet = new HashSet<>();
                    if (StringUtils.isNotEmpty(gwmc)) {
                        String[] gwmcArr = gwmc.split("；");
                        String gwmcSql = "SELECT id FROM uf_JCL_GWGL ";
                        for (int i = 0; i < gwmcArr.length; i++) {
                            if (i == 0) {
                                gwmcSql = gwmcSql + " WHERE gwmc LIKE '%" + gwmcArr[i] + "%' ";
                            } else {
                                gwmcSql = gwmcSql + " OR gwmc LIKE '%" + gwmcArr[i] + "%' ";
                            }
                        }

                        rs1.execute(gwmcSql);
                        while (rs1.next()) {
                            String dataIdT = rs1.getString("id");
                            if (StringUtils.isNotEmpty(dataIdT)) {
                                gwmcSet.add(dataIdT);
                            }
                        }
                    }
                    String zj = rysxTemp.get("zj");

                    if (StringUtils.isEmpty(ygzt) && StringUtils.isEmpty(bm) && (StringUtils.isEmpty(sfbmtdfzr) || StringUtils.equals(sfbmtdfzr, "1"))
                            && StringUtils.isEmpty(rylb) && StringUtils.isEmpty(rzkssj) && StringUtils.isEmpty(rzjssj) && StringUtils.isEmpty(lzkssj)
                            && StringUtils.isEmpty(lzjssj) && StringUtils.isEmpty(rzts) && StringUtils.isEmpty(xxbmtd)
                            && StringUtils.isEmpty(sfbhq) && StringUtils.isEmpty(zwxl) && StringUtils.isEmpty(gwmc) && StringUtils.isEmpty(gw) && StringUtils.isEmpty(zj)) {
                        sqlA = sqlA + " AND 1=2 ";
                    }
                    baseBean.writeLog("jdUpgradeCount sqlA:" + sqlA);
                    rs1.execute(sqlA);
                    while (rs1.next()) {
                        String idT = rs1.getString("id");
                        String gwT = rs1.getString("gw");
                        String zjT = rs1.getString("zj");
                        if (StringUtils.isNotEmpty(gw)) {
                            if (StringUtils.isEmpty(gwT)) {
                                continue;
                            }
                            List<String> list = Arrays.asList(gw.split(","));
                            if (!list.contains(gwT)) {
                                continue;
                            }
                        }
                        if (StringUtils.isNotEmpty(gwmc)) {
                            if (StringUtils.isEmpty(gwT)) {
                                continue;
                            }
                            if (CollectionUtils.isEmpty(gwmcSet) || !gwmcSet.contains(gwT)) {
                                continue;
                            }
                        }
                        if (StringUtils.isNotEmpty(zwxl)) {
                            if (StringUtils.isEmpty(gwT)) {
                                continue;
                            }
                            if (CollectionUtils.isEmpty(gwSet) || !gwSet.contains(gwT)) {
                                continue;
                            }
                        }
                        if (StringUtils.isNotEmpty(zj)) {
                            if (StringUtils.isEmpty(zjT)) {
                                continue;
                            }
                            List<String> list = Arrays.asList(zj.split(","));
                            if (!list.contains(zjT)) {
                                continue;
                            }
                        }
                        if (StringUtils.equals(sfbhq, "0")) {
                            if (CollectionUtils.isEmpty(protectSet) || !protectSet.contains(idT)) {
                                continue;
                            }
                        }
                        if (StringUtils.equals(sfbhq, "1")) {
                            if ((!CollectionUtils.isEmpty(protectSet)) && protectSet.contains(idT)) {
                                continue;
                            }
                        }

                        if (StringUtils.isNotEmpty(gwbdsxkssj) && ((new BigDecimal(gwbdsxkssj).compareTo(new BigDecimal("1")) >= 0
                                && new BigDecimal(gwbdsxkssj).compareTo(new BigDecimal(String.valueOf(lastDayFirst))) <= 0) || new BigDecimal(gwbdsxkssj).compareTo(new BigDecimal("99")) == 0)) {
                            String ddrqTemp = ddrqMap.get(idT);
                            if (StringUtils.isEmpty(ddrqTemp)) {
                                continue;
                            }
                            String rqTemp = "";
                            if (new BigDecimal(gwbdsxkssj).compareTo(new BigDecimal("99")) == 0) {
                                rqTemp = yearMonthFirst.atDay(lastDayFirst).toString();
                            } else {
                                rqTemp = yearMonthFirst.atDay(Integer.parseInt(gwbdsxkssj)).toString();
                            }
                            if (LocalDate.parse(ddrqTemp, formatter).isBefore(LocalDate.parse(rqTemp, formatter))) {
                                continue;
                            }
                        }

                        if (StringUtils.isNotEmpty(gwbdsxsjjs) && ((new BigDecimal(gwbdsxsjjs).compareTo(new BigDecimal("1")) >= 0
                                && new BigDecimal(gwbdsxsjjs).compareTo(new BigDecimal(String.valueOf(lastDay))) <= 0) || new BigDecimal(gwbdsxsjjs).compareTo(new BigDecimal("99")) == 0)) {
                            String ddrqTemp = ddrqMap.get(idT);
                            if (StringUtils.isEmpty(ddrqTemp)) {
                                continue;
                            }
                            String rqTemp = "";
                            if (new BigDecimal(gwbdsxsjjs).compareTo(new BigDecimal("99")) == 0) {
                                rqTemp = yearMonth1.atDay(lastDay).toString();
                            } else {
                                rqTemp = yearMonth1.atDay(Integer.parseInt(gwbdsxsjjs)).toString();
                            }
                            if (!LocalDate.parse(ddrqTemp, formatter).isBefore(LocalDate.parse(rqTemp, formatter))) {
                                continue;
                            }
                        }

                        if (StringUtils.isNotEmpty(zxgwbdsxts)) {
                            String ddrqTemp = ddrqMap.get(idT);
                            if (StringUtils.isEmpty(ddrqTemp)) {
                                continue;
                            }
                            long daysBetween = ChronoUnit.DAYS.between(LocalDate.parse(ddrqTemp, formatter), LocalDate.parse(jhksrq, formatter));
                            if (daysBetween < 0) {
                                daysBetween = -daysBetween;
                            }
                            if (new BigDecimal(String.valueOf(daysBetween)).compareTo(new BigDecimal(zxgwbdsxts)) <= 0) {
                                continue;
                            }
                        }
                        rySet.add(idT);
                    }

                    String jtry = rysxTemp.get("jtry");
                    if (StringUtils.isNotEmpty(jtry)) {
                        rySet.addAll(Arrays.asList(jtry.split(",")));
                    }
                }
            }

            if (CollectionUtils.isEmpty(rySet)) {
                baseBean.writeLog("jdUpgradeCount rySet is null.");
                result.put("mes", "未查到需生成指标的员工，请检查！");
                result.put("code", "200");
                return result;
            }
            baseBean.writeLog("jdUpgradeCount rySet size is:" + rySet.size());

            // 获取指标排序逻辑
            List<String> zbList = new ArrayList<>();
            List<Map<String, String>> zbMapList = new ArrayList<>();
            Map<String, Map<String, String>> zbMapMap = new HashMap<>();
            if (StringUtils.isNotEmpty(pmtjlj)) {
                rs.execute("select * from uf_jdsjzbpxlj_dt1 where mainid = " + pmtjlj + " order by pxzbsx");
                while (rs.next()) {
                    String zb = rs.getString("zb");
                    String pxfs = rs.getString("pxfs");
                    String pxzbzb = rs.getString("pxzbzb");
                    String pxzbsx = rs.getString("pxzbsx");
                    Map<String, String> zbMapTemp = new HashMap<>();
                    zbMapTemp.put("zb", zb);
                    zbMapTemp.put("pxfs", pxfs);
                    zbMapTemp.put("pxzbzb", pxzbzb);
                    zbMapTemp.put("pxzbsx", pxzbsx);
                    zbMapMap.put(zb, zbMapTemp);
                    zbMapList.add(zbMapTemp);
                    zbList.add(zb);
                }
            }

            if (StringUtils.isNotEmpty(pmtjlj) && CollectionUtils.isEmpty(zbList)) {
                baseBean.writeLog("jdUpgradeCount zbList is null.");
                result.put("mes", "请检查指标排序逻辑！");
                result.put("code", "200");
                return result;
            }

            Map<String, String> ewsxMap = new HashMap<>();
            // 获取额外筛选条件
            if (StringUtils.isNotEmpty(pmewsxtj)) {
                rs.execute("select * from uf_JDSJPMEWSXTJ_dt1 where mainid = " + pmewsxtj);
                while (rs.next()) {
                    String zb = rs.getString("zb");
                    String jslj = rs.getString("jslj");
                    String pdz = rs.getString("pdz");
                    if (StringUtils.isEmpty(jslj) || StringUtils.isEmpty(pdz)) {
                        continue;
                    }
                    ewsxMap.put(zb, jslj + "_" + pdz);
                }
            }
            if (StringUtils.isNotEmpty(pmewsxtj) && CollectionUtils.isEmpty(ewsxMap)) {
                baseBean.writeLog("jdUpgradeCount ewsxMap is null.");
                result.put("mes", "请检查额外筛选条件！");
                result.put("code", "200");
                return result;
            }

            String querySql = "SELECT a.*, b.id as ygid FROM uf_wczjgb a LEFT JOIN hrmresource b ON a.yggh = b.workcode " +
                    " WHERE 1 = 1 ";
            if (StringUtils.isNotEmpty(pmtjlj)) {
                querySql = querySql + " AND a.zbid in (" + String.join(",", zbList) + ") ";
            }

            Map<String, Map<String, String>> zbdfMap = new HashMap<>();
            rs.execute(querySql);
            while (rs.next()) {
                String ygid = rs.getString("ygid");
                if (StringUtils.isEmpty(ygid) || !rySet.contains(ygid)) {
                    continue;
                }
                String szny = rs.getString("szny");
                if (StringUtils.isEmpty(szny) || !nyList.contains(szny)) {
                    continue;
                }
                String zbid = rs.getString("zbid");
                String wcz = rs.getString("wcz");
                if (StringUtils.isEmpty(wcz)) {
                    wcz = "0";
                }
                Map<String, String> zbdfMapTemp = new HashMap<>();
                if ((!CollectionUtils.isEmpty(zbdfMap)) && zbdfMap.containsKey(ygid)) {
                    zbdfMapTemp = zbdfMap.get(ygid);
                }
                if ((!CollectionUtils.isEmpty(zbdfMapTemp)) && zbdfMapTemp.containsKey(zbid)) {
                    String s = zbdfMapTemp.get(zbid);
                    if (StringUtils.isEmpty(s)) {
                        s = "0";
                    }
                    zbdfMapTemp.put(zbid, new BigDecimal(wcz).add(new BigDecimal(s)).toString());
                } else {
                    zbdfMapTemp.put(zbid, wcz);
                }
                zbdfMap.put(ygid, zbdfMapTemp);
            }

            if (CollectionUtils.isEmpty(zbdfMap)) {
                baseBean.writeLog("jdUpgradeCount zbdfMap is null.");
                result.put("mes", "无完成值数据需要计算！");
                result.put("code", "200");
                return result;
            }

            Map<String, String> zdfMap = new HashMap<>();
            for (Map.Entry<String, Map<String, String>> mapEntry : zbdfMap.entrySet()) {
                Map<String, String> value = mapEntry.getValue();
                String ygKey = mapEntry.getKey();
                if (CollectionUtils.isEmpty(value)) {
                    continue;
                }
                String zdf = "0";
                boolean isContinue = true;
                for (Map.Entry<String, String> strMap : value.entrySet()) {
                    String key = strMap.getKey();
                    String value1 = strMap.getValue();
                    if (StringUtils.isEmpty(value1)) {
                        value1 = "0";
                    }
                    BigDecimal v1Bd = new BigDecimal(value1);
                    if (StringUtils.isNotEmpty(pmewsxtj)) {
                        if (ewsxMap.containsKey(key)) {
                            String s1 = ewsxMap.get(key);
                            String gs = s1.split("_")[0];
                            String pdz = s1.split("_")[1];
                            if (StringUtils.isEmpty(pdz)) {
                                pdz = "0";
                            }
                            BigDecimal pdzBd = new BigDecimal(pdz);
                            if (StringUtils.equals(gs, "0")) {
                                if (v1Bd.compareTo(pdzBd) == 0) {
                                    continue;
                                } else {
                                    isContinue = false;
                                    break;
                                }
                            } else if (StringUtils.equals(gs, "1")) {
                                if (v1Bd.compareTo(pdzBd) > 0) {
                                    continue;
                                } else {
                                    isContinue = false;
                                    break;
                                }
                            } else if (StringUtils.equals(gs, "2")) {
                                if (v1Bd.compareTo(pdzBd) >= 0) {
                                    continue;
                                } else {
                                    isContinue = false;
                                    break;
                                }
                            } else if (StringUtils.equals(gs, "3")) {
                                if (v1Bd.compareTo(pdzBd) < 0) {
                                    continue;
                                } else {
                                    isContinue = false;
                                    break;
                                }
                            } else if (StringUtils.equals(gs, "4")) {
                                if (v1Bd.compareTo(pdzBd) <= 0) {
                                    continue;
                                } else {
                                    isContinue = false;
                                    break;
                                }
                            }
                        }
                    }
                    String valueTemp = value1;
                    if (StringUtils.isNotEmpty(pmtjlj) && zbMapMap.containsKey(key)) {
                        String pxzbzb = zbMapMap.get(key).get("pxzbzb");
                        if (StringUtils.isEmpty(pxzbzb)) {
                            pxzbzb = "0";
                        }
                        valueTemp = new BigDecimal(value1).multiply(new BigDecimal(pxzbzb)).toString();
                    }
                    zdf = new BigDecimal(zdf).add(new BigDecimal(valueTemp)).toString();
                }

                if (!isContinue) {
                    continue;
                }
                zdfMap.put(ygKey, zdf);
            }

            if (CollectionUtils.isEmpty(zdfMap)) {
                baseBean.writeLog("jdUpgradeCount zdfMap is null.");
                result.put("mes", "无完成值数据需要计算！");
                result.put("code", "200");
                return result;
            }

            baseBean.writeLog("jdUpgradeCount zdfMap is:" + JSONObject.toJSONString(zdfMap));

            List<Map.Entry<String, String>> list = new ArrayList<>(zdfMap.entrySet());

            // 定义一个Comparator，根据Map的value（数值型字符串）进行降序排序
            Comparator<Map.Entry<String, String>> comparatorOne = (entry1, entry2) -> {
                // 将字符串 value 转换为浮点数进行比较
                double value1 = Double.parseDouble(entry1.getValue());
                double value2 = Double.parseDouble(entry2.getValue());

                // 返回负值表示 entry1 应排在 entry2 之前，正值则相反，零表示相等
                return Double.compare(value2, value1); // 降序排序
            };
            // 对List进行排序
            Collections.sort(list, comparatorOne);

            Map<String, Integer> ygpmOneMap = new HashMap<>();
            int pmIndex = 1;
            String oldDf = "-1";
            String oldYg = "0";
            List<Set<String>> setList = new ArrayList<>();
            Set<String> sameList = new HashSet<>();
            for (Map.Entry<String, String> entry : list) {
                String xdf = entry.getValue();
                String xyg = entry.getKey();
                if (new BigDecimal(oldDf).compareTo(new BigDecimal(xdf)) == 0) {
                    sameList.add(oldYg);
                    sameList.add(xyg);
                } else {
                    if (!CollectionUtils.isEmpty(sameList)) {
                        setList.add(sameList);
                        sameList = new HashSet<>();
                    }
                }
                oldDf = xdf;
                oldYg = xyg;
                ygpmOneMap.put(entry.getKey(), pmIndex);
                pmIndex = pmIndex + 1;
            }

            if (!CollectionUtils.isEmpty(setList)) {
                baseBean.writeLog("jdUpgradeCount setList is:" + setList);
            } else {
                baseBean.writeLog("jdUpgradeCount is null.");
            }
            // 如果存在相同得分，则进一步细化比较
            if (!CollectionUtils.isEmpty(setList)) {
                for (Set<String> setIds : setList) {
                    Map<String, Integer> idOrderMap = new HashMap<>();
                    List<Map<String, String>> mapList = new ArrayList<>();
                    for (String idA : setIds) {
                        String rankStr = ygpmOneMap.get(idA) + "";
                        if (StringUtils.isEmpty(rankStr)) {
                            rankStr = "0";
                        }
                        idOrderMap.put(idA, Integer.parseInt(rankStr));
                        Map<String, String> mapNew = zbdfMap.get(idA);
                        // 插入排序
                        if (!CollectionUtils.isEmpty(mapList)) {
                            for (int i = 0; i < mapList.size(); i++) {
                                boolean isBreakA = false;
                                Map<String, String> mapOld = mapList.get(i);
                                for (int j = 0; j < zbList.size(); j++) {
                                    String zbT = zbList.get(j);
                                    String wczNew = mapNew.get(zbT);
                                    String wczOld = mapOld.get(zbT);
                                    if (StringUtils.isEmpty(wczNew) && StringUtils.isEmpty(wczOld)) {
                                        if (j == zbList.size() - 1) {
                                            mapList.add(mapNew);
                                            isBreakA = true;
                                            break;
                                        }
                                    } else {
                                        if (StringUtils.isEmpty(wczNew)) {
                                            mapList.add(mapNew);
                                            isBreakA = true;
                                            break;
                                        }
                                        if (StringUtils.isEmpty(wczOld)) {
                                            mapList.add(i, mapNew);
                                            isBreakA = true;
                                            break;
                                        }
                                        BigDecimal wczNewBd = new BigDecimal(wczNew);
                                        BigDecimal wczOldBd = new BigDecimal(wczOld);

                                        String pxfsT = zbMapMap.get(zbT).get("pxfs");

                                        if (wczNewBd.compareTo(wczOldBd) == 0) {
                                            if (j == zbList.size() - 1) {
                                                mapList.add(mapNew);
                                                isBreakA = true;
                                                break;
                                            }
                                        } else if (wczNewBd.compareTo(wczOldBd) > 0) {
                                            if (StringUtils.equals(pxfsT, "0")) {
                                                mapList.add(mapNew);
                                                isBreakA = true;
                                                break;
                                            } else {
                                                mapList.add(i, mapNew);
                                                isBreakA = true;
                                                break;
                                            }
                                        } else {
                                            if (StringUtils.equals(pxfsT, "0")) {
                                                mapList.add(i, mapNew);
                                                isBreakA = true;
                                                break;
                                            } else {
                                                mapList.add(mapNew);
                                                isBreakA = true;
                                                break;
                                            }
                                        }
                                    }
                                }
                                if (isBreakA) {
                                    break;
                                }
                            }
                        } else {
                            mapList.add(mapNew);
                        }
                    }

                    List<Integer> sortedValues = idOrderMap.values().stream()
                            .sorted() // 使用自然顺序排序
                            .collect(Collectors.toList());

                    for (int i = 0; i < mapList.size(); i++) {
                        Map<String, String> map = mapList.get(i);
                        Iterator<String> keyIterator = map.keySet().iterator();
                        String ygKey = keyIterator.next();
                        Integer sortedValue = sortedValues.get(i);
                        if (sortedValue == null) {
                            sortedValue = 0;
                        }
                        ygpmOneMap.put(ygKey, sortedValue);
                    }
                }
            }

            if (CollectionUtils.isEmpty(ygpmOneMap)) {
                baseBean.writeLog("jdUpgradeCount ygpmOneMap is null.");
                result.put("mes", "无满足条件的员工数据！");
                result.put("code", "200");
                return result;
            }
            baseBean.writeLog("jdUpgradeCount ygpmOneMap is:" + ygpmOneMap);
            baseBean.writeLog("jdUpgradeCount sjfw is:" + sjfw);
            // 季度升级结果建模id
            String modeId = rs.getPropValue("qz_jx_zm_prop", "jd_upgrade_res_mode_id");
            // 季度升级结果查询id
            String cusId = rs.getPropValue("qz_jx_zm_prop", "jd_upgrade_res_cus_id");
            SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");

            if (StringUtils.isEmpty(sjfw)) {
                sjfw = "0";
            }
            int size = ygpmOneMap.size();
            String upgradeSizeStr = "0";
            if (StringUtils.equals(fwqzlj, "0")) {
                upgradeSizeStr = new BigDecimal(String.valueOf(size)).multiply(new BigDecimal(sjfw)).setScale(0, RoundingMode.UP).toString();
            } else if (StringUtils.equals(fwqzlj, "1")) {
                upgradeSizeStr = new BigDecimal(String.valueOf(size)).multiply(new BigDecimal(sjfw)).setScale(0, RoundingMode.DOWN).toString();
            } else {
                upgradeSizeStr = new BigDecimal(String.valueOf(size)).multiply(new BigDecimal(sjfw)).setScale(0, RoundingMode.HALF_UP).toString();
            }

            int upgradeSize = Integer.parseInt(upgradeSizeStr);
            List<List> insertList = new ArrayList<>();
            List<List> insertListOther = new ArrayList<>();

            // 获取人员对应分部、部门、聚才林岗位
            Map<String, String> idAndGhMap = new HashMap<>();
            Map<String, String> fbMap = new HashMap<>();
            Map<String, String> bmMap = new HashMap<>();
            Map<String, String> gwMap = new HashMap<>();
            rs.execute("SELECT a.id,a.workcode,a.subcompanyid1,a.departmentid,b." + gwFieldId + " FROM hrmresource a LEFT JOIN cus_fielddata b " +
                    " ON a.id = b.id AND b.scope = 'HrmCustomFieldByInfoType' AND b.scopeid = 3 ");
            while (rs.next()) {
                String ryIdT = rs.getString("id");
                String subcompanyid1 = rs.getString("subcompanyid1");
                String departmentid = rs.getString("departmentid");
                String workcode = rs.getString("workcode");
                String jclGw = rs.getString(gwFieldId);
                if (StringUtils.isEmpty(ryIdT) || StringUtils.isEmpty(subcompanyid1) || StringUtils.isEmpty(departmentid)
                        || StringUtils.isEmpty(workcode)) {
                    continue;
                }
                idAndGhMap.put(ryIdT, workcode);
                fbMap.put(ryIdT, subcompanyid1);
                bmMap.put(ryIdT, departmentid);
                gwMap.put(ryIdT, jclGw);
            }

//            int cnt = 1;
            for (Map.Entry<String, Integer> insertMap : ygpmOneMap.entrySet()) {
                String yg = insertMap.getKey();
                String yggh = idAndGhMap.get(yg);
                String szfb = fbMap.get(yg);
                String szbm = bmMap.get(yg);
                String szgw = gwMap.get(yg);
                Integer pm = insertMap.getValue();
                List listTemp = new ArrayList<>();
                if (pm <= upgradeSize) {
                    listTemp.add(jdsjkhfa);
                    listTemp.add(yg);
                    listTemp.add(zjbdlb);
                    listTemp.add(xcdzje);
                    listTemp.add(pm);
                    listTemp.add(nf);
                    listTemp.add(jd);
                    listTemp.add("0");
                    listTemp.add(szfb);
                    listTemp.add(szbm);
                    listTemp.add(szgw);
                    listTemp.add(yggh);
                    listTemp.add(modeId);
                    listTemp.add(cusId);
                    listTemp.add("1");
                    listTemp.add("0");
                    listTemp.add(sdfDate.format(new Date()));
                    listTemp.add(sdfTime.format(new Date()));
                    insertList.add(listTemp);
                } else {
                    listTemp.add(jdsjkhfa);
                    listTemp.add(yg);
                    listTemp.add(pm);
                    listTemp.add(nf);
                    listTemp.add(jd);
                    listTemp.add("1");
                    listTemp.add(szfb);
                    listTemp.add(szbm);
                    listTemp.add(szgw);
                    listTemp.add(yggh);
                    listTemp.add(modeId);
                    listTemp.add(cusId);
                    listTemp.add("1");
                    listTemp.add("0");
                    listTemp.add(sdfDate.format(new Date()));
                    listTemp.add(sdfTime.format(new Date()));
                    insertListOther.add(listTemp);
                }
//                cnt = cnt + 1;
            }

            if (CollectionUtils.isEmpty(insertList)) {
                baseBean.writeLog("jdUpgradeCount insertList is null.");
            } else {
                baseBean.writeLog("jdUpgradeCount insertList size is:" + insertList.size());
                String insertSql = "INSERT INTO uf_jdsjjgb (szjdsjkhfa,yg,zjbdlb,xcdzje,pm,sznf,szjd,sfzsjfw,szfb,szbm,szgw,yggh,formmodeid, MODEUUID, modedatacreater," +
                        "modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                rs.executeBatchSql(insertSql, insertList);
            }

            if (CollectionUtils.isEmpty(insertListOther)) {
                baseBean.writeLog("jdUpgradeCount insertListOther is null.");
            } else {
                baseBean.writeLog("jdUpgradeCount insertListOther size is:" + insertListOther.size());
                String insertSql = "INSERT INTO uf_jdsjjgb (szjdsjkhfa,yg,pm,sznf,szjd,sfzsjfw,szfb,szbm,szgw,yggh,formmodeid, MODEUUID, modedatacreater," +
                        "modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                rs.executeBatchSql(insertSql, insertListOther);
            }

            // 权限重构
            ModeRightInfo modeRightInfo = new ModeRightInfo();
            modeRightInfo.setNewRight(true);
            modeRightInfo.editModeDataShare(1, Integer.parseInt(modeId), Integer.parseInt(cusId));
        } catch (Exception e) {
            baseBean.writeLog("jdUpgradeCount error:" + e);
            result.put("mes", "系统错误，请联系管理员！");
            result.put("code", "400");
            return result;
        }
        baseBean.writeLog("jdUpgradeCount end.");
        result.put("mes", "正在计算，请稍等！");
        result.put("code", "200");
        return result;
    }

    @Override
    public Map<String, Object> hrmOwnDataCount(Map<String, Object> params) {
        Map<String, Object> result = new HashMap<>();
        baseBean.writeLog("hrmOwnDataCount start:" + params);
        try {
            // 年月
            String nyParam = Util.null2String(params.get("ny"));
            if (StringUtils.isEmpty(nyParam)) {
                baseBean.writeLog("hrmOwnDataCount ny is null.");
                result.put("mes", "请选择计算的月份！");
                result.put("code", "200");
                return result;
            }

            RecordSet rs = new RecordSet();
            RecordSet rs1 = new RecordSet();
            RecordSet rs2 = new RecordSet();

            SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
            SimpleDateFormat dtFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            DateTimeFormatter yearMonthFormatter = DateTimeFormatter.ofPattern("yyyy-MM");
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

            Set<String> nySet = new HashSet<>();
            nySet.add(nyParam);

            // 获取指定角色成员
            // 角色“DF_人资中心总”id
            String roleId = baseBean.getPropValue("qz_jx_zm_prop", "df_hrm_boss_role_id");
            Set<String> roleSet = new HashSet<>();
            rs.execute("SELECT RESOURCEID FROM hrmrolemembers WHERE ROLEID = " + roleId);
            while (rs.next()) {
                String id = rs.getString("RESOURCEID");
                if (StringUtils.isNotEmpty(id)) {
                    roleSet.add(id);
                }
            }

            // 转正日期fieldId 3
            String zzDateFieldId = rs.getPropValue("qz_jx_zm_prop", "zz_date_field_id");
            // 集团分部ids
            String groupFbIds = rs.getPropValue("qz_jx_zm_prop", "group_fb_ids");

            List<List> insertParams = new ArrayList<>();
            // 人事系统自有业务数据建模id
            String modeId = rs.getPropValue("qz_jx_zm_prop", "hrm_own_mode_id");
            // 人事系统自有业务数据查询id
            String cusId = rs.getPropValue("qz_jx_zm_prop", "hrm_own_cus_id");

            String gwFieldId = rs.getPropValue("qz_jx_zm_prop", "gw_field_id");

            String querySqlNew = " SELECT a1.*, e." + gwFieldId + " FROM (SELECT b.yg,b.szkhjh,c.szny, d.workcode, d.subcompanyid1, d.departmentid FROM uf_ygmxzbdy_dt1 a, uf_ygmxzbdy b, uf_khjhdy c, hrmresource d " +
                    " WHERE a.mainid = b.id and b.szkhjh = c.id AND b.yg = d.id AND a.zbid = ? AND c.szny = ? ) a1 " +
                    " LEFT JOIN cus_fielddata e ON e.id = a1.yg AND e.scope = 'HrmCustomFieldByInfoType' AND e.scopeid = 3 ";
            String querySqlTempNew = "SELECT id FROM uf_rsxtzyywsjb where yg = ? and ny = ? and zb = ?";
            String sql = "SELECT * FROM uf_rlzbjspzglb WHERE zt is null or zt != 0";
            rs.execute(sql);
            while (rs.next()) {
                String zb = rs.getString("zb");
                String fwsql = rs.getString("fwsql");
                String jszb = rs.getString("jszb");
                String ts = rs.getString("ts");
                if (StringUtils.isEmpty(zb) || StringUtils.isEmpty(fwsql) || StringUtils.isEmpty(jszb)) {
                    continue;
                }
                if (StringUtils.isEmpty(ts)) {
                    ts = "0";
                }
                // "净增人数"暂时不做; "绩效偏离度"不在这里处理
                if (StringUtils.equals(jszb, "4") || StringUtils.equals(jszb, "2")) {
                    continue;
                }
                for (String ny : nySet) {
                    Set<String> rySet = new HashSet<>();
                    Map<String, String> ghMap = new HashMap<>();
                    Map<String, String> fbMap = new HashMap<>();
                    Map<String, String> bmMap = new HashMap<>();
                    Map<String, String> gwMap = new HashMap<>();
                    rs1.executeQuery(querySqlNew, zb, ny);
                    while (rs1.next()) {
                        String ygTemp = rs1.getString("yg");
                        String workcode = rs1.getString("workcode");
                        String subcompanyid1 = rs1.getString("subcompanyid1");
                        String departmentid = rs1.getString("departmentid");
                        String szgw = rs1.getString(gwFieldId);
                        if (StringUtils.isEmpty(ygTemp) || StringUtils.isEmpty(workcode)) {
                            continue;
                        }
                        rySet.add(ygTemp);
                        ghMap.put(ygTemp, workcode);
                        fbMap.put(ygTemp, subcompanyid1);
                        bmMap.put(ygTemp, departmentid);
                        gwMap.put(ygTemp, szgw);
                    }

                    if (CollectionUtils.isEmpty(rySet)) {
                        continue;
                    }
                    String resValueT = "0";

                    String fwsqlTemp = fwsql;
                    String firstDayT = ny + "-01";
                    String lastDayT = YearMonth.parse(ny, yearMonthFormatter).atEndOfMonth().toString();
                    String ryfwbdsql = fwsqlTemp.replace("$ksrq$", firstDayT).replace("$jsrq$", lastDayT);

                    List<String> dataIdSet = new ArrayList<>();
                    rs1.execute(ryfwbdsql);
                    while (rs1.next()) {
                        String dataId = rs1.getString(1);
                        if (StringUtils.isEmpty(dataId)) {
                            continue;
                        }
                        dataIdSet.add(dataId);
                    }

                    if (CollectionUtils.isEmpty(dataIdSet)) {
                        continue;
                    }
                    int batchSize = 1000; // 每个小集合的大小
                    int size = dataIdSet.size(); // 原始集合的大小
                    int numberOfBatches = (int) Math.ceil((double) size / batchSize); // 划分的小集合数量
                    List<List<String>> dividedLists = new ArrayList<>(); // 存储划分后的小集合

                    for (int i = 0; i < numberOfBatches; i++) {
                        int fromIndex = i * batchSize;
                        int toIndex = Math.min((i + 1) * batchSize, size);
                        List<String> batch = dataIdSet.subList(fromIndex, toIndex);
                        dividedLists.add(batch);
                    }

                    // 干部满编率、满编率
                    if (StringUtils.equals(jszb, "0") || StringUtils.equals(jszb, "7")) {
                        String zbs = "0";
                        rs1.execute("select t1.id,t1.szfb,t1.bzfa ,t1.szbm,cast(t1.szgw  as varchar(1000))  jcljobtitle ,max(t1.bzs) bzs ,\n" +
                                "count(t5.id) zbs,max(t1.bzs)-count(t5.id) qbs,\n" +
                                "case when max(t1.bzs)-count(t5.id) >0 then '0' \n" +
                                "when max(t1.bzs)-count(t5.id) <0 then '2'\n" +
                                "else '1' end as QK\n" +
                                "from uf_bzqkhz t1\n" +
                                "left join uf_bzfagl t2 on t1.bzfa=t2.id\n" +
                                "left join uf_bzfagl_dt1 t3 on t2.id=t3.mainid\n" +
                                "left join hrmresource t4 on t1.szbm=t4.departmentid\n" +
                                "and t4.usekind in (select * from split(t3.yglx,','))\n" +
                                "and t4.status in (0,1,2,3)\n" +
                                "left join cus_fielddata t5 on t5.id=t4.id and t5.scopeid=3 and t5.field13 in\n" +
                                "(select * from split(t1.szgw,','))\n" +
                                "where (t2.bzwd= '0' or t2.bzwd='3')\n" +
                                "group by t1.szfb,t1.szbm,t1.id,t1.bzfa,cast(t1.szgw  as varchar(1000))");
                        while (rs1.next()) {
                            String idT = rs1.getString("id");
                            if (StringUtils.isEmpty(idT)) {
                                continue;
                            }
                            if (!dataIdSet.contains(idT)) {
                                continue;
                            }
                            String zbsT = rs1.getString("zbs");
                            if (StringUtils.isEmpty(zbsT)) {
                                zbsT = "0";
                            }
                            zbs = new BigDecimal(zbs).add(new BigDecimal(zbsT)).toString();
                        }

                        String bzs = "0";
                        for (List<String> batch : dividedLists) {
                            String ids = String.join(",", batch);
                            rs1.execute("SELECT id,bzs FROM uf_bzqkhz WHERE id in (" + ids + ")");
                            while (rs1.next()) {
                                String bzsT = rs1.getString("bzs");
                                if (StringUtils.isEmpty(bzsT)) {
                                    bzsT = "0";
                                }
                                bzs = new BigDecimal(bzs).add(new BigDecimal(bzsT)).toString();
                            }
                        }
                        if (new BigDecimal(bzs).compareTo(BigDecimal.ZERO) > 0) {
                            BigDecimal resValueBd = new BigDecimal(zbs).divide(new BigDecimal(bzs), 8, RoundingMode.DOWN);
                            if (resValueBd.compareTo(BigDecimal.ZERO) == 0) {
                                resValueT = "0";
                            } else {
                                resValueT = resValueBd.toString();
                            }
                        }
                    } else if (StringUtils.equals(jszb, "1")) {  // 顾问转正率
                        int zzrs = 0;
                        int yzzrs = 0;
                        LocalDate lastDayLd = LocalDate.parse(lastDayT, formatter);
                        YearMonth dqnyFormatter = YearMonth.parse(ny, yearMonthFormatter);
                        for (List<String> batch : dividedLists) {
                            String ids = String.join(",", batch);
                            rs1.execute("SELECT a.id,a.probationenddate,a.subcompanyid1,a.usekind,b." + zzDateFieldId + " as zzrq " +
                                    " FROM hrmresource a, cus_fielddata b where a.id = b.id and b.scope = 'HrmCustomFieldByInfoType' " +
                                    "and scopeid = 3 AND a.id in (" + ids + ")");
                            while (rs1.next()) {
                                String probationenddate = rs1.getString("probationenddate");
                                String zzrq = rs1.getString("zzrq");

                                if (StringUtils.isNotEmpty(zzrq)) {
                                    LocalDate date = LocalDate.parse(zzrq, formatter);
                                    if (!date.isAfter(lastDayLd)) {
                                        zzrs = zzrs + 1;
                                    }
                                }
                                if (StringUtils.isNotEmpty(probationenddate)) {
                                    LocalDate date = LocalDate.parse(probationenddate, formatter);
                                    YearMonth dateYearMonth = YearMonth.from(date);
                                    if (dqnyFormatter.equals(dateYearMonth)) {
                                        yzzrs = yzzrs + 1;
                                    }
                                }
                            }
                        }

                        if (yzzrs > 0) {
                            BigDecimal resValueBd = new BigDecimal(String.valueOf(zzrs)).divide(new BigDecimal(String.valueOf(yzzrs)), 8, RoundingMode.DOWN);
                            if (resValueBd.compareTo(BigDecimal.ZERO) == 0) {
                                resValueT = "0";
                            } else {
                                resValueT = resValueBd.toString();
                            }
                        }
                    } else if (StringUtils.equals(jszb, "2")) {  // 绩效偏离度

                    } else if (StringUtils.equals(jszb, "3")) {  // 离职人数
                        String firstDay = ny + "-01";
                        String lastDay = ny + "-31";
                        Set<String> lzSet = new HashSet<>();
                        rs1.execute("select resourceid from HRMSTATUSHISTORY  where type_n = 5 " +
                                "and changedate >= '" + firstDay + "' and changedate <= '" + lastDay + "'");
                        while (rs1.next()) {
                            String resourceid = rs1.getString("resourceid");
                            if (StringUtils.isNotEmpty(resourceid)) {
                                lzSet.add(resourceid);
                            }
                        }
                        if (!CollectionUtils.isEmpty(lzSet)) {
                            int cnt = 0;
                            for (String ry : dataIdSet) {
                                if (lzSet.contains(ry)) {
                                    cnt = cnt + 1;
                                }
                            }
                            resValueT = String.valueOf(cnt);
                        }
                    } else if (StringUtils.equals(jszb, "5")) {  // 离职率
                        String firstDay = ny + "-01";
                        YearMonth dqnyFormatter = YearMonth.parse(ny, yearMonthFormatter);
                        String lastDay = dqnyFormatter.atEndOfMonth().toString();
                        // 获取在职人员
                        Set<String> zzSet = new HashSet<>();
                        rs1.execute("select distinct t1.yg from uf_rzjl t1 where '" + lastDay + "' >= shenxrq  and '"
                                + lastDay + "' <= t1.sxrq and t1.bdhzt<=3");
                        while (rs1.next()) {
                            zzSet.add(rs1.getString("yg"));
                        }
                        Set<String> lzSet = new HashSet<>();
                        rs1.execute("select resourceid,changedate from HRMSTATUSHISTORY  where type_n = 5 " +
                                "and changedate <= '" + lastDay + "' and changedate >= '" + firstDay + "'");
                        while (rs1.next()) {
                            String resourceid = rs1.getString("resourceid");
                            String changedate = rs1.getString("changedate");
                            if (StringUtils.isNotEmpty(resourceid) && StringUtils.isNotEmpty(changedate)) {
                                lzSet.add(resourceid);
                            }
                        }
                        if (!CollectionUtils.isEmpty(lzSet)) {
                            int lzCnt = 0;
                            int zzCnt = 0;
                            for (String ry : dataIdSet) {
                                if (zzSet.contains(ry)) {
                                    zzCnt = zzCnt + 1;
                                }
                                if (lzSet.contains(ry)) {
                                    lzCnt = lzCnt + 1;
                                    zzCnt = zzCnt + 1;
                                }
                            }
                            if (lzCnt > 0 && zzCnt > 0) {
                                BigDecimal resValueBd = new BigDecimal(String.valueOf(lzCnt)).divide(new BigDecimal(String.valueOf(zzCnt)), 8, RoundingMode.DOWN);
                                if (resValueBd.compareTo(BigDecimal.ZERO) == 0) {
                                    resValueT = "0";
                                } else {
                                    resValueT = resValueBd.toString();
                                }
                            }
                        }
                    } else if (StringUtils.equals(jszb, "6")) {  // 分司新人留存率
                        YearMonth yearMonth = YearMonth.parse(ny, yearMonthFormatter);
                        // 获取该月的第一天
                        LocalDate firstDayOfMonth = yearMonth.atDay(1);
                        // 获取该月的最后一天
                        LocalDate lastDayOfMonth = yearMonth.atEndOfMonth();
                        LocalDate startDateLd = firstDayOfMonth.minusDays(Integer.parseInt(ts));
                        LocalDate endDateLd = lastDayOfMonth.minusDays(Integer.parseInt(ts));
                        Set<String> lzSet = new HashSet<>();
                        rs1.execute("select resourceid from HRMSTATUSHISTORY  where type_n = 5 " +
                                "and changedate <= '" + lastDayOfMonth + "' and changedate >= '" + startDateLd + "'");
                        while (rs1.next()) {
                            String resourceid = rs1.getString("resourceid");
                            if (StringUtils.isNotEmpty(resourceid)) {
                                lzSet.add(resourceid);
                            }
                        }
                        int rzry = 0;
                        int lzry = 0;
                        rs1.execute("SELECT id FROM hrmresource WHERE companystartdate >= '" + startDateLd + "' " +
                                " AND companystartdate <= '" + endDateLd + "'");
                        while (rs1.next()) {
                            String id = rs1.getString("id");
                            if (StringUtils.isEmpty(id)) {
                                continue;
                            }
                            if (!dataIdSet.contains(id)) {
                                continue;
                            }
                            rzry = rzry + 1;
                            if ((!CollectionUtils.isEmpty(lzSet)) && lzSet.contains(id)) {
                                lzry = lzry + 1;
                            }
                        }
                        if (rzry > 0 && lzry >= 0 && rzry != lzry) {
                            int fz = rzry - lzry;
                            BigDecimal valueBd = new BigDecimal(String.valueOf(fz)).divide(new BigDecimal(rzry), 8, RoundingMode.DOWN);
                            if (valueBd.compareTo(BigDecimal.ZERO) != 0) {
                                resValueT = valueBd.toString();
                            }
                        }
                    }

                    for (String yg : rySet) {
                        String workcode = ghMap.get(yg);
                        String szfb = fbMap.get(yg);
                        String szbm = bmMap.get(yg);
                        String szgw = gwMap.get(yg);
                        if (StringUtils.isEmpty(workcode) || StringUtils.isEmpty(szfb) || StringUtils.isEmpty(szbm) || StringUtils.isEmpty(szgw)) {
                            continue;
                        }
                        rs1.executeQuery(querySqlTempNew, yg, ny, zb);
                        int dataId = 0;
                        if (rs1.next()) {
                            dataId = rs1.getInt("id");
                        }
                        if (dataId > 0) {
                            rs1.executeUpdate("UPDATE uf_rsxtzyywsjb SET wcz = ?, szfb = ?, szbm = ?, szgw = ?, modedatamodifydatetime = ? WHERE id= ?",
                                    resValueT, szfb, szbm, szgw, dtFormat.format(new Date()), dataId);
                        } else {
                            List insertParam = new ArrayList<>();
                            insertParam.add(yg);
                            insertParam.add(workcode);
                            insertParam.add(ny);
                            insertParam.add(zb);
                            insertParam.add(resValueT);
                            insertParam.add(szfb);
                            insertParam.add(szbm);
                            insertParam.add(szgw);
                            insertParam.add(modeId);
                            insertParam.add(cusId);
                            insertParam.add("1");
                            insertParam.add("0");
                            insertParam.add(sdfDate.format(new Date()));
                            insertParam.add(sdfTime.format(new Date()));
                            insertParams.add(insertParam);
                        }
                    }
                }
            }

            if (CollectionUtils.isEmpty(insertParams)) {
                baseBean.writeLog("insertParams is null.");
            } else {
                baseBean.writeLog("insertParams size is:" + insertParams.size());
            }
            if (!CollectionUtils.isEmpty(insertParams)) {
                String insertSql = "INSERT INTO uf_rsxtzyywsjb (yg,gh,ny,zb,wcz,szfb,szbm,szgw,formmodeid, MODEUUID, modedatacreater," +
                        "modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                rs.executeBatchSql(insertSql, insertParams);
            }
            // 权限重构
            ModeRightInfo modeRightInfo = new ModeRightInfo();
            modeRightInfo.setNewRight(true);
            modeRightInfo.editModeDataShare(1, Integer.parseInt(modeId), Integer.parseInt(cusId));
        } catch (Exception e) {
            baseBean.writeLog("hrmOwnDataCount error:" + e);
            result.put("mes", "系统错误，请联系管理员！");
            result.put("code", "400");
            return result;
        }
        baseBean.writeLog("hrmOwnDataCount end.");
        result.put("mes", "正在计算，请稍等！");
        result.put("code", "200");
        return result;
    }

    public void updateWczjgData(String jhSzny) {
        baseBean.writeLog("updateWczjgData start.");
        try {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");

            // 将字符串解析为YearMonth对象
            YearMonth specifiedYearMonth = YearMonth.parse(jhSzny, formatter);

            // 获取前三个月的YearMonth对象
            YearMonth threeMonthsAgo = specifiedYearMonth.minusMonths(3);
            YearMonth twoMonthsAgo = specifiedYearMonth.minusMonths(2);
            YearMonth oneMonthAgo = specifiedYearMonth.minusMonths(1);

            // 将YearMonth对象格式化为字符串
            String threeMonthsAgoStr = threeMonthsAgo.format(formatter);
            String twoMonthsAgoStr = twoMonthsAgo.format(formatter);
            String oneMonthAgoStr = oneMonthAgo.format(formatter);
            Set<String> nySet = new HashSet<>();
            nySet.add(jhSzny);
            nySet.add(threeMonthsAgoStr);
            nySet.add(twoMonthsAgoStr);
            nySet.add(oneMonthAgoStr);

            RecordSet wczRs = new RecordSet();
            Map<String, String> mapJgb = new HashMap<>();
            wczRs.executeQuery("SELECT * FROM uf_wczjgb where szny = ? or szny = ? or szny = ? or szny = ?", jhSzny, threeMonthsAgoStr, twoMonthsAgoStr,
                    oneMonthAgoStr);
            while (wczRs.next()) {
                String id = wczRs.getString("id");
                String yggh = wczRs.getString("yggh");
                String zbid = wczRs.getString("zbid");
                String szny = wczRs.getString("szny");
                String sjly = wczRs.getString("sjly");
                String key = yggh + "-" + zbid + "-" + szny + "-" + sjly;
                mapJgb.put(key, id);
            }

            SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd");
            SimpleDateFormat sdfTime = new SimpleDateFormat("HH:mm:ss");
            SimpleDateFormat dtFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            // 完成值结果表中系统自有数据下拉选id
            String selectId = wczRs.getPropValue("qz_jx_zm_prop", "hrm_own_select_item_id");
            // 完成值结果表中BI系统下拉选id
            String biSelectId = wczRs.getPropValue("qz_jx_zm_prop", "BI_select_item_id");
            // 完成值结果表中手动维护下拉选id
            String handAddSelectId = wczRs.getPropValue("qz_jx_zm_prop", "hand_add_select_item_id");
            // 完成值结果表中流程下拉选id
            String wfSelectId = wczRs.getPropValue("qz_jx_zm_prop", "wf_select_item_id");
            // 完成值结果表中薪资二次计算下拉选id
            String xzSelectId = wczRs.getPropValue("qz_jx_zm_prop", "salary_cnt_again_select_item_id");
            // 完成值结果建模id
            String modeId = wczRs.getPropValue("qz_jx_zm_prop", "wczjgb_mode_id");
            // 完成值结果查询id
            String cusId = wczRs.getPropValue("qz_jx_zm_prop", "wczjgb_cus_id");

            String gwFieldId = wczRs.getPropValue("qz_jx_zm_prop", "gw_field_id");

            List<List> updateList = new ArrayList<>();
            List<List> insertList = new ArrayList<>();

            Map<String, String> idMap = new HashMap<>();
            Map<String, String> fbMap = new HashMap<>();
            Map<String, String> bmMap = new HashMap<>();
            Map<String, String> gwMap = new HashMap<>();
            wczRs.execute("SELECT a.id, a.subcompanyid1, a.departmentid, b." + gwFieldId + ", a.workcode " +
                    " FROM hrmresource a " +
                    " LEFT JOIN cus_fielddata b ON b.id = a.id AND b.scope = 'HrmCustomFieldByInfoType' AND b.scopeid = 3 ");
            while (wczRs.next()) {
                String id = wczRs.getString("id");
                String workcode = wczRs.getString("workcode");
                String subcompanyid1 = wczRs.getString("subcompanyid1");
                String departmentid = wczRs.getString("departmentid");
                String szgw = wczRs.getString(gwFieldId);
                if (StringUtils.isEmpty(id) || StringUtils.isEmpty(workcode) || StringUtils.isEmpty(subcompanyid1)
                        || StringUtils.isEmpty(departmentid) || StringUtils.isEmpty(szgw)) {
                    continue;
                }
                idMap.put(workcode, id);
                fbMap.put(workcode, subcompanyid1);
                bmMap.put(workcode, departmentid);
                gwMap.put(workcode, szgw);
            }
            // 自有数据
            wczRs.executeQuery("select * from uf_rsxtzyywsjb where ny = ? or ny = ? or ny = ? or ny = ?", jhSzny, threeMonthsAgoStr, twoMonthsAgoStr,
                    oneMonthAgoStr);
            while (wczRs.next()) {
                String gh = wczRs.getString("gh");
                String ny = wczRs.getString("ny");
                String zb = wczRs.getString("zb");
                String wcz = wczRs.getString("wcz");
                if (StringUtils.isEmpty(gh) || StringUtils.isEmpty(ny) || StringUtils.isEmpty(zb)) {
                    continue;
                }
                String ryid = idMap.get(gh);
                String szfb = fbMap.get(gh);
                String szbm = bmMap.get(gh);
                String szgw = gwMap.get(gh);
                String key = gh + "-" + zb + "-" + ny + "-" + selectId;
                if ((!CollectionUtils.isEmpty(mapJgb)) && mapJgb.containsKey(key)) {
                    String id = mapJgb.get(key);
                    List arrayList = new ArrayList<>();
                    arrayList.add(wcz);
                    arrayList.add(dtFormat.format(new Date()));
                    arrayList.add(szfb);
                    arrayList.add(szbm);
                    arrayList.add(szgw);
                    arrayList.add(id);
                    updateList.add(arrayList);
                } else {
                    List arrayList = new ArrayList<>();
                    arrayList.add(gh);
                    arrayList.add(zb);
                    arrayList.add(wcz);
                    arrayList.add(ny);
                    arrayList.add(selectId);
                    arrayList.add(ryid);
                    arrayList.add(szfb);
                    arrayList.add(szbm);
                    arrayList.add(szgw);
                    arrayList.add(modeId);
                    arrayList.add(cusId);
                    arrayList.add("1");
                    arrayList.add("0");
                    arrayList.add(sdfDate.format(new Date()));
                    arrayList.add(sdfTime.format(new Date()));
                    insertList.add(arrayList);
                }
            }

            // 获取指标编码映射
            Map<String, String> zbbmMap = new HashMap<>();
            wczRs.execute("SELECT * FROM uf_BIXTZBYS");
            while (wczRs.next()) {
                String bizbbm = wczRs.getString("bizbbm");
                String zbTemp = wczRs.getString("zb");
                if (StringUtils.isEmpty(bizbbm) || StringUtils.isEmpty(zbTemp)) {
                    continue;
                }
                zbbmMap.put(bizbbm, zbTemp);
            }

            // BI系统中间表
            wczRs.executeQuery("select a.*,b.workcode from uf_BIxtzjb a, hrmresource b WHERE a.yg = b.id and (a.szzq " +
                    "= ? or a.szzq = ? or a.szzq = ? or a.szzq = ?)", jhSzny, threeMonthsAgoStr, twoMonthsAgoStr, oneMonthAgoStr);
            while (wczRs.next()) {
                String gh = wczRs.getString("workcode");
                String ny = wczRs.getString("szzq");
                String zb = wczRs.getString("zbxm");
                String wcz = wczRs.getString("wcz");
                if (StringUtils.isEmpty(gh) || StringUtils.isEmpty(ny) || StringUtils.isEmpty(zb)) {
                    continue;
                }
                if (CollectionUtils.isEmpty(zbbmMap)) {
                    continue;
                }
                zb = zbbmMap.get(zb);
                if (StringUtils.isEmpty(zb)) {
                    continue;
                }
                String ryid = idMap.get(gh);
                String szfb = fbMap.get(gh);
                String szbm = bmMap.get(gh);
                String szgw = gwMap.get(gh);
                String key = gh + "-" + zb + "-" + ny + "-" + biSelectId;
                if ((!CollectionUtils.isEmpty(mapJgb)) && mapJgb.containsKey(key)) {
                    String id = mapJgb.get(key);
                    List arrayList = new ArrayList<>();
                    arrayList.add(wcz);
                    arrayList.add(dtFormat.format(new Date()));
                    arrayList.add(szfb);
                    arrayList.add(szbm);
                    arrayList.add(szgw);
                    arrayList.add(id);
                    updateList.add(arrayList);
                } else {
                    List arrayList = new ArrayList<>();
                    arrayList.add(gh);
                    arrayList.add(zb);
                    arrayList.add(wcz);
                    arrayList.add(ny);
                    arrayList.add(biSelectId);
                    arrayList.add(ryid);
                    arrayList.add(szfb);
                    arrayList.add(szbm);
                    arrayList.add(szgw);
                    arrayList.add(modeId);
                    arrayList.add(cusId);
                    arrayList.add("1");
                    arrayList.add("0");
                    arrayList.add(sdfDate.format(new Date()));
                    arrayList.add(sdfTime.format(new Date()));
                    insertList.add(arrayList);
                }
            }

            // 手动维护台账
            wczRs.executeQuery("select * from uf_zbwczsdwhglb where szzq = ? or szzq = ? or szzq = ? or szzq = ?", jhSzny, threeMonthsAgoStr, twoMonthsAgoStr, oneMonthAgoStr);
            while (wczRs.next()) {
                String gh = wczRs.getString("gh");
                String ny = wczRs.getString("szzq");
                String zb = wczRs.getString("zbxm");
                String wcz = wczRs.getString("wcz");
                if (StringUtils.isEmpty(gh) || StringUtils.isEmpty(ny) || StringUtils.isEmpty(zb)) {
                    continue;
                }
                String ryid = idMap.get(gh);
                String szfb = fbMap.get(gh);
                String szbm = bmMap.get(gh);
                String szgw = gwMap.get(gh);
                String key = gh + "-" + zb + "-" + ny + "-" + handAddSelectId;
                if ((!CollectionUtils.isEmpty(mapJgb)) && mapJgb.containsKey(key)) {
                    String id = mapJgb.get(key);
                    List arrayList = new ArrayList<>();
                    arrayList.add(wcz);
                    arrayList.add(dtFormat.format(new Date()));
                    arrayList.add(szfb);
                    arrayList.add(szbm);
                    arrayList.add(szgw);
                    arrayList.add(id);
                    updateList.add(arrayList);
                } else {
                    List arrayList = new ArrayList<>();
                    arrayList.add(gh);
                    arrayList.add(zb);
                    arrayList.add(wcz);
                    arrayList.add(ny);
                    arrayList.add(handAddSelectId);
                    arrayList.add(ryid);
                    arrayList.add(szfb);
                    arrayList.add(szbm);
                    arrayList.add(szgw);
                    arrayList.add(modeId);
                    arrayList.add(cusId);
                    arrayList.add("1");
                    arrayList.add("0");
                    arrayList.add(sdfDate.format(new Date()));
                    arrayList.add(sdfTime.format(new Date()));
                    insertList.add(arrayList);
                }
            }

            // 流程
            wczRs.executeQuery("select * from uf_zbwczlcsjglb where szzq = ? or szzq = ? or szzq = ? or szzq = ?", jhSzny, threeMonthsAgoStr, twoMonthsAgoStr, oneMonthAgoStr);
            while (wczRs.next()) {
                String gh = wczRs.getString("gh");
                String ny = wczRs.getString("szzq");
                String zb = wczRs.getString("zbxm");
                String wcz = wczRs.getString("wcz");
                if (StringUtils.isEmpty(gh) || StringUtils.isEmpty(ny) || StringUtils.isEmpty(zb)) {
                    continue;
                }
                String ryid = idMap.get(gh);
                String szfb = fbMap.get(gh);
                String szbm = bmMap.get(gh);
                String szgw = gwMap.get(gh);
                String key = gh + "-" + zb + "-" + ny + "-" + wfSelectId;
                if ((!CollectionUtils.isEmpty(mapJgb)) && mapJgb.containsKey(key)) {
                    String id = mapJgb.get(key);
                    List arrayList = new ArrayList<>();
                    arrayList.add(wcz);
                    arrayList.add(dtFormat.format(new Date()));
                    arrayList.add(szfb);
                    arrayList.add(szbm);
                    arrayList.add(szgw);
                    arrayList.add(id);
                    updateList.add(arrayList);
                } else {
                    List arrayList = new ArrayList<>();
                    arrayList.add(gh);
                    arrayList.add(zb);
                    arrayList.add(wcz);
                    arrayList.add(ny);
                    arrayList.add(wfSelectId);
                    arrayList.add(ryid);
                    arrayList.add(szfb);
                    arrayList.add(szbm);
                    arrayList.add(szgw);
                    arrayList.add(modeId);
                    arrayList.add(cusId);
                    arrayList.add("1");
                    arrayList.add("0");
                    arrayList.add(sdfDate.format(new Date()));
                    arrayList.add(sdfTime.format(new Date()));
                    insertList.add(arrayList);
                }
            }

            baseBean.writeLog("salary count start.");
            // 薪资二次计算
            wczRs.execute("select a.employee_id as yg, c.workcode as gh, a.result_value, b.salary_month, d.zbxm " +
                    " from hrsa_salary_acct_result a,hrsa_salary_acct_record b,hrmresource c, uf_xzxmyzbysglb d " +
                    " where a.salary_acct_record_id = b.id and a.employee_id = c.id and a.salary_item_id = d.xzxm ");
            while (wczRs.next()) {
                String gh = wczRs.getString("gh");
                String nyT = wczRs.getString("salary_month");
                String zb = wczRs.getString("zbxm");
                String wcz = wczRs.getString("result_value");
                if (StringUtils.isEmpty(gh) || StringUtils.isEmpty(nyT) || StringUtils.isEmpty(zb)) {
                    continue;
                }
                String ny = nyT.substring(0, 7);
                if (!nySet.contains(ny)) {
                    continue;
                }
                String ryid = idMap.get(gh);
                String szfb = fbMap.get(gh);
                String szbm = bmMap.get(gh);
                String szgw = gwMap.get(gh);
                if (StringUtils.isNotEmpty(wcz)) {
                    wcz = SalaryReportUtil.decrypt(wcz);
                }
                String key = gh + "-" + zb + "-" + ny + "-" + xzSelectId;
                if ((!CollectionUtils.isEmpty(mapJgb)) && mapJgb.containsKey(key)) {
                    String id = mapJgb.get(key);
                    List arrayList = new ArrayList<>();
                    arrayList.add(wcz);
                    arrayList.add(dtFormat.format(new Date()));
                    arrayList.add(szfb);
                    arrayList.add(szbm);
                    arrayList.add(szgw);
                    arrayList.add(id);
                    updateList.add(arrayList);
                } else {
                    List arrayList = new ArrayList<>();
                    arrayList.add(gh);
                    arrayList.add(zb);
                    arrayList.add(wcz);
                    arrayList.add(ny);
                    arrayList.add(xzSelectId);
                    arrayList.add(ryid);
                    arrayList.add(szfb);
                    arrayList.add(szbm);
                    arrayList.add(szgw);
                    arrayList.add(modeId);
                    arrayList.add(cusId);
                    arrayList.add("1");
                    arrayList.add("0");
                    arrayList.add(sdfDate.format(new Date()));
                    arrayList.add(sdfTime.format(new Date()));
                    insertList.add(arrayList);
                }
            }

            if (CollectionUtils.isEmpty(updateList)) {
                baseBean.writeLog("updateList is null.");
            } else {
                baseBean.writeLog("updateList size is:" + updateList.size());
                String updateSql = "UPDATE uf_wczjgb SET wcz = ?, modedatamodifydatetime = ?, szfb = ?, szbm = ?," +
                        " szgw = ? WHERE id = ?";
                wczRs.executeBatchSql(updateSql, updateList);
            }

            if (CollectionUtils.isEmpty(insertList)) {
                baseBean.writeLog("insertList is null.");
            } else {
                baseBean.writeLog("insertList size is:" + insertList.size());
                String insertSql = "INSERT INTO uf_wczjgb (yggh,zbid,wcz,szny,sjly,ry,szfb,szbm,szgw,formmodeid, MODEUUID, modedatacreater," +
                        "modedatacreatertype, modedatacreatedate, modedatacreatetime) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                wczRs.executeBatchSql(insertSql, insertList);
            }

            // 权限重构
            ModeRightInfo modeRightInfo = new ModeRightInfo();
            modeRightInfo.setNewRight(true);
            modeRightInfo.editModeDataShare(1, Integer.parseInt(modeId), Integer.parseInt(cusId));
        } catch (Exception e) {
            baseBean.writeLog("updateWczjgData error:" + e);
        }
        baseBean.writeLog("updateWczjgData end.");
    }
}
